2011-08-28 83 views
8

我在網上找到了一些代碼,我編輯了一下。我想隱藏JInternalFrame的標題欄。隱藏JInternalFrame的標題欄? -java

JInternalFrame frame = new JInternalFrame(); 
    // Get the title bar and set it to null 
    setRootPaneCheckingEnabled(false); 
    javax.swing.plaf.InternalFrameUI ifu= frame.getUI(); 
    ((javax.swing.plaf.basic.BasicInternalFrameUI)ifu).setNorthPane(null);  

    frame.setLocation(i*50+10, i*50+10); 
    frame.setSize(200, 150); 
    //frame.setBackground(Color.white);  

    frame.setVisible(true); 
    desktop.add(frame); 

問題是標題欄並未因某些原因而被隱藏。 謝謝。

回答

11

首先將內部幀轉換爲基本內部幀。

像這樣做: -

BasicInternalFrameUI bi = (BasicInternalFrameUI)your_internalframe_object.getUI(); 
bi.setNorthPane(null); 

這個標題欄後,將是不可見的。

10

我用這種方法解決了這個問題:我將子類JInternalFrame添加到它的構造函數中。 (我得到的子類的自由,因爲我使用NetBeans的GUI構建器)

((javax.swing.plaf.basic.BasicInternalFrameUI)this.getUI()).setNorthPane(null); 

你的情況,我認爲

+0

不錯,這是正確的答案,不像.setUI(null)!我還在某處看到,在某些事件發生後(如最小化窗口),您可能需要重新執行此操作。 –

+0

這是正確的答案。與'frame.setBorder(null);'結合使用['JInternalFrame'](https://docs.oracle.com/javase/8/docs/api/javax/swing/JInternalFrame.html )作爲頂級['JFrame'](http://docs.oracle.com/javase/8/docs/api/javax/swing/JFrame.html)中的獨奏組件,就好像它是['JPanel '](http://docs.oracle.com/javase/8/docs/api/javax/swing/JPanel.html)。 – vallismortis

+0

爲我工作。我甚至不會嘗試,但像魅力一樣。謝謝。 – George

0

這對我來說工作得非常好:

putClientProperty("JInternalFrame.isPalette", Boolean.TRUE); 
    getRootPane().setWindowDecorationStyle(JRootPane.NONE); 
    ((BasicInternalFrameUI) this.getUI()).setNorthPane(null); 
    this.setBorder(null); 

感謝。