I make my first baby steps in Java and Swing GUI. My plan is to make a little GUI with an JTextArea to fill in some text and two tabbed JPanels. But the problem is, when I fill in some text in the JTextArea and click the tab "Includes" (or the other tab "Functions"), it resizes the tabmenu (It should have a fixed 50:50 view).
Here are some pictures for a better understanding:
Here is the Java code:
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
public class Editor extends JFrame {
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
Editor editor = new Editor();
}
private JTextArea guiEdit = new JTextArea();
private JScrollPane utilScrollbar = new JScrollPane(guiEdit);
private JTabbedPane guiOverviewTabPanel = new JTabbedPane();
private JPanel guiOverviewTabIncludes = new JPanel();
private JPanel guiOverviewTabFunctions = new JPanel();
public Editor() {
// Set layout
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
setLayout(gridbag);
// Add the textfield
c.fill = GridBagConstraints.BOTH;
c.gridx = 0;
c.gridy = 0;
c.gridheight = 1;
c.weightx = 1.0;
c.weighty = 1.0;
c.anchor = GridBagConstraints.WEST;
add(utilScrollbar, c);
// Add tabs to the JTabbedPane
guiOverviewTabPanel.add("Includes", guiOverviewTabIncludes);
guiOverviewTabPanel.add("Functions", guiOverviewTabFunctions);
// Add the JTabbedPane
c.fill = GridBagConstraints.BOTH;
c.gridx = 1;
c.gridy = 0;
c.gridheight = 1;
c.weightx = 1.0;
c.weighty = 1.0;
c.anchor = GridBagConstraints.EAST;
add(guiOverviewTabPanel, c);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
this.setMinimumSize(new Dimension(800, 400));
setVisible(true);
}
}
Does anyone know a way/solution to fix this perspective. The real ratio ist 5:2 (5 parts JTextArea and 2 parts JTabbedPane - this is just for a better understanding, so I can't use a GridLayout