This is because the BorderLayout.PAGE_START will respect the preferred height of the component added. Now, when you decrease the width the components disappear. ![]() The issue is your expectation.Ĭhange the code in your first example: //frame.getContentPane().add(panel, BorderLayout.CENTER) įrame.getContentPane().add(panel, BorderLayout.PAGE_START) The preferred approach since then is to add the "constraint" as the second parameter: frame.getContentPane().add(panel, BorderLayout.CENTER) īut it is enough to put one JPanel into another JPanel and layout manager stops to behave as expected: It seems reasonable, but still not clear for me why I got inconsistent behavior in the examples above.įirst of all that method has been "obsolete" since JDK1.1. I've read a lot of suggestions to use WrapLayout instead of FlowLayout. I'm trying to clarify what I misunderstood. JButton button3 = new JButton("Button 3") įrame.getContentPane().add(BorderLayout.CENTER, panel) īut it is enough to put one JPanel into another JPanel and layout manager stops to behave as expected: import javax.swing.* įrame.getContentPane().add(BorderLayout.CENTER, outerPanel) JButton button2 = new JButton("Button 2") JButton button1 = new JButton("Button 1") For example, while using this code and decreasing window width, buttons will be located on different rows: import javax.swing.* If the horizontal space in the container is too small to put all the components in one row, the FlowLayout class uses multiple rows. This assumption is based on the documentation: ![]() I think in case the application window was resized and there is not enough width to show all components in JPanel in one row, some components will be moved to another row(s). ![]() I'm using JPanel with a default FlowLayout layout manager.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |