2012-12-06 33 views
1

所以我有另外一個問題.....重疊JSplitPane的在Jbutton將BorderLayout的,但不會在佈局空

我目前使用的BorderLayout在我的GUI,這樣,當我調整我的JFrame,所有內部組件都會隨之調整大小。我無法獲得任何其他佈局,以便在提供此調整大小功能的同時處理GUI的外觀。在頂部,我有一個JMenuBar,在它的下面有一堆按鈕。在下面我應該有一個JSplitPane,它在那裏。但是,按鈕似乎被包含在JSplitPane中,這不是我的意圖。所以當分割面板發生任何事情時,按鈕會消失,直到我再次將鼠標移到它們上面爲止。

當我將佈局設置爲null時,除非丟失了調整大小的功能,否則一切都很好。

嘗試發佈的圖像,但它不會讓我,因爲我的心不是代表在10尚未:(

有什麼建議? 我試圖把按鈕進入一個JPanel然後添加的JPanel,但在將splitPane與重疊。 。同樣的,一個JToolBar中

中添加我的項目的順序是:

1)菜單欄

setJMenuBar(menuBar) 

2)按鈕

getContentPane().add(btnZoomIn) 

3)拆分窗格

getContentPane().add(splitPane) 

那麼之後你

+0

得到了一些代碼,證明這個問題?或屏幕截圖?從它的外觀來看,你應該添加按鈕到'getContentPane().add(btnZoomIn,BorderLayout.NORTH)'作爲邊框佈局只允許一個組件位於UI的中心位置 – MadProgrammer

+0

這裏是空佈局 http ://imgur.com/1X1h7 這裏的邊界佈局 http://imgur.com/xMQUm 也響應borderlayout.north:我已經關掉它,這樣我加入我的每一個6個按鈕到一個jtoolbar,然後在北部地區添加,那就做了訣竅。我的按鈕現在看起來很奇怪,因爲它們在工具欄中,但是很好。感謝您的建議!它幫助了很多 – thaweatherman

回答

2

看到剩下的事情似乎爲我工作得很好...

enter image description here

public class BadLayout06 { 

    public static void main(String[] args) { 
     new BadLayout06(); 
    } 

    public BadLayout06() { 
     EventQueue.invokeLater(new Runnable() { 
      @Override 
      public void run() { 
       try { 
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
       } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { 
       } 

       JMenuBar mb = new JMenuBar(); 
       mb.add(new JMenu("File")); 

       JToolBar tb = new JToolBar(); 
       tb.add(new JButton("Zoom In")); 
       tb.add(new JButton("Zoom Out")); 
       tb.add(new JButton("Invert Image")); 
       tb.add(new JButton("Toggle Highlights")); 
       tb.add(new JButton("Save")); 
       tb.add(new JButton("Cancel")); 
       tb.setFloatable(false); 

       JSplitPane spSub = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); 
       JTabbedPane tpLeft = new JTabbedPane(); 
       tpLeft.add("Table Entry", new JPanel()); 
       tpLeft.add("Form Entry", new JPanel()); 
       spSub.setLeftComponent(tpLeft); 
       JTabbedPane tpRight = new JTabbedPane(); 
       tpRight.add("Field Help", new JPanel()); 
       tpRight.add("Image Navigation", new JPanel()); 
       spSub.setRightComponent(tpRight); 


       JSplitPane spMain = new JSplitPane(JSplitPane.VERTICAL_SPLIT); 
       spMain.setLeftComponent(new JPanel()); 
       spMain.setRightComponent(spSub); 


       JFrame frame = new JFrame("Testing"); 
       frame.setJMenuBar(mb); 
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
       frame.setLayout(new BorderLayout()); 
       frame.add(tb, BorderLayout.NORTH); 
       frame.add(spMain, BorderLayout.CENTER); 
       frame.pack(); 
       frame.setLocationRelativeTo(null); 
       frame.setVisible(true); 
      } 
     }); 
    } 

} 
+0

是的,在北部的位置添加了jtoolbar爲我工作。謝謝! – thaweatherman