2012-09-05 56 views
2

是否有可能創建一個具有框架和邊框,但沒有標題按鈕(最小化,還原,關閉)的Java某種窗口對象。我可以使用Java創建一個沒有標題按鈕的窗口嗎?

當然,我不能使用​​設置。此外,該窗口需要:

  • 有一個平臺渲染邊界
  • 有一個標題欄
  • 無標題按鈕。如果需要,我會照顧通過編程方式處理窗口。
  • 使用默認,或System外觀和感覺

下面是一個例子:

captionless window

+0

看看這個線程放在那裏,它會幫助你:http://stackoverflow.com/questions/2665355/how-do-i-remove-the-maximize-and-最小化按鈕從一個jframe – lebryant

+0

http://docs.oracle.com/javase/7/docs/technotes/guides/swing/1.4/w2k_props.html –

+0

或者你也可以使用JWindow而不是JFrame這樣的例子如上。它不會有那3個通常的按鈕 – lebryant

回答

4

簡短的答案是否定的。

較長的答案是,可能是,但你需要調查一個JNI/JNA實現

+2

...和它的長短是...它可能不值得在大多數情況下 – Redandwhite

+0

努力不知道(作爲你提到你是Java1.3 dinosaurus,我來自Java1.6.09)直到Java1.4都可以改變DecorationsType而不限制頂級容器+1 – mKorbel

2

試試這個小例子。它將從JFrame中刪除(不僅禁用)最小化,最大化和關閉按鈕。

import javax.swing.*; 
import java.awt.*; 
import java.awt.event.*; 

class Example { 

    public void buildGUI() { 
     JFrame.setDefaultLookAndFeelDecorated(true); 
     JFrame frame = new JFrame(); 
     frame.setResizable(false); 
     removeButtons(frame); 
     JPanel panel = new JPanel(new GridBagLayout()); 
     JButton button = new JButton("Exit"); 
     panel.add(button,new GridBagConstraints()); 
     frame.getContentPane().add(panel); 
     frame.setSize(400,300); 
     frame.setLocationRelativeTo(null); 
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     frame.setVisible(true); 
     button.addActionListener(new ActionListener(){ 
      public void actionPerformed(ActionEvent a){ 
       System.exit(0); 
      } 
     }); 
    } 

    public void removeButtons(Component comp) { 
     if(comp instanceof AbstractButton) { 
      comp.getParent().remove(comp); 
     } 
     if (comp instanceof Container) { 
      Component[] comps = ((Container)comp).getComponents(); 
      for(int x=0, y=comps.length; x<y; x++) { 
       removeButtons(comps[x]); 
      } 
     } 
    } 

    public static void main(String[] args) { 
     SwingUtilities.invokeLater(new Runnable(){ 
      public void run(){ 
       new Example().buildGUI(); 
      } 
     }); 
    } 
} 
+1

不是一個壞的嘗試。但是,窗口不可調整大小。另外,一個要求是它使用系統外觀。改變系統的外觀和感覺就會毀了它。結果:在左邊的示例中,修改相同的內容以使用默認外觀:http://i.imgur.com/pFSRy.png – Redandwhite

5

這是關於

  1. 體面How to Create Translucent and Shaped Windows

  2. 未修飾JDialogCompound Borders,那麼你就可以創建similair或更好的邊框從本地OS來

  3. 創建JPanel(或JLabel#opaque(true))與GradientPaint

  4. 或(更好non_focusable ==我的看法)JLabel與準備Icon

  5. 添加到JPanel/JLabelComponent Mover/Component Resize(注意,不要從不混合這兩個碼在一起)由@camickr

  6. 設置Alpha Transparency繪畫在JPanel/JLabel偉大look and feel

  7. 最簡單的方式JMenuBar

相關問題