Reputation: 164
I have a JPanel that uses BorderLayout and contains a jTable and a layeredPane. I need to use the layeredPane because it contains a jComboBox on top of a jTextPane. The problem is that when the user resizes the screen, the layeredPane doesn't resize. How can i fix this? I have something like this:
JPanel panel = new JPanel(new Borderlayout());
MyTable table = new MyTable();
panel.add(table, BorderLayout.CENTER);
JLayeredPane layeredPane = new JLayeredPane();
//addind things in the layered pane
panel.add(layeredPane, BorderLayout.PAGE_END);
Using a layout manager for the layered pane won't work, because i need components to be overlapped.
Upvotes: 0
Views: 725
Reputation: 109815
common issue about JLayeredPane is that its childs would be placed by setBounds, because doesn't supports Standards LayoutManagers excluding Null Layout
have to add ComponentListener on event componentResized to change JPanels Bounds
for JComponents placed to the JPanel to use Standard LayoutManager
more than an alternative is to use the proper JLayer for Java7 based on custom JXLayer for Java6
Upvotes: 1
Reputation: 10143
In the example you have posted JLayeredPane takes the SOUTH (BorderLayout.PAGE_END) place in the panel with BorderLayout. That means that the component in CENTER will take all additional space offered to the panel. And you have your table in CENTER.
Just place JLayeredPane in the CENTER and table in the NORTH to let the pane take all additional space.
More on BorderLayout:
http://docs.oracle.com/javase/tutorial/uiswing/layout/border.html
You also might want to read more on Swing layouts:
http://docs.oracle.com/javase/tutorial/uiswing/layout/index.html
Upvotes: 1