Content
- Overview
- Code example
- Screenshots of the problem
1. Overview of the problem
So, I am writing a graphical interface for a complex program that I am developing, and I am tired of trying to properly scale the components when the window is resized.
At first, I used several layouts inside jframe, and each jpanel tried to position components correctly and scale them correctly. Naturally, I got tired of them, and I started trying to scale and dynamically set the x, y positions of the components (this is much simpler: D).
I mainly try to split the screen into three fields on the left (JSplitPane), center (JTabbedPane) and right field (JSplitPane). I do not think that internal components matter at this point. The main problem : the correct JSplitPane scales across the window, despite the fact that I used setBounds () to put x, y on the right and set the size to 21% of the total width. It seems to be interacting with other panels.
2. Code Example
import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JSplitPane; import javax.swing.JTabbedPane; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.awt.Dimension; @SuppressWarnings("deprecation") public class test extends JFrame implements WindowListener { private final double LEFT_SIZE = .21; private final double CENTER_SIZE = .58; private final double RIGHT_SIZE = .21; private final int TOP_PADDING = 50; private final int LEFT_PADDING = 4; private final int RIGHT_PADDING = 4; private final int BOTTOM_PADDING = 4; private final int MIN_WIDTH = 640; private final int MIN_HEIGHT = 480; public static final String INIT_TITLE = "TestFrame v0.01"; private int contentWidth; private int contentHeight; public static test window; private JSplitPane left; private JButton button1; private JButton button2; private JTabbedPane center; private JPanel panel1; private JPanel panel2; private JSplitPane right; private JButton button3; private JButton button4; public test ( String windowName ) { super(windowName);
3. Screenshots


source share