フレームの下部にJTextAreaがあり、幅全体に広がるSwingアプリケーションがあります。ユーザーが間違えると、JTextAreaにエラーメッセージが表示されます。これが起こると、右側の2つの列が広くなり、左側の2つの列が狭くなります。私はいたるところを検索しましたが、これを止める方法を見つけることができません。誰かが私がこれを修正する方法を説明できますか?私のGUIのコードを以下に示します。
public GUI(Event event) {
super("Checkpoint Manager");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setLocation(165,25);
listener = new Listener(event, this);
// Initializes labels and text fields.
arrivalLabel = new JLabel("Arrival Time: ");
depLabel = new JLabel("Departure Time: ");
checkLabel = new JLabel("Tick For Exclusion: ");
SimpleDateFormat format = new SimpleDateFormat("HH:mm");
arrival = new JFormattedTextField(format);
dep = new JFormattedTextField(format);
check = new JCheckBox();
// Initializes panel and buttons, also adds ActionListeners to buttons.
panel = new JPanel();
panel.setLayout(new GridBagLayout());
setLayout(new FlowLayout());
submit = new JButton("Submit");
cancel = new JButton("Cancel");
enterMed = new JButton("Enter Medical Checkpoint");
enterTime = new JButton("Enter Time Checkpoint");
submit.addActionListener(listener);
cancel.addActionListener(listener);
enterMed.addActionListener(listener);
enterTime.addActionListener(listener);
// Initializes the messageArea and sets the border for it.
messageArea = new JTextArea();
messageArea.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createCompoundBorder
(BorderFactory.createTitledBorder("Messages"),BorderFactory.createEmptyBorder(5,5,5,5)),messageArea.getBorder()));
// Initializes the ScrollPane for the timeList and adds the timeList to it.
entrantModel = new DefaultListModel();
entrantList = new JList(entrantModel);
entrantList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
entrantPane = new JScrollPane(entrantList);
entrantPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createCompoundBorder
(BorderFactory.createTitledBorder("Entrants"),BorderFactory.createEmptyBorder(5,5,5,5)),entrantPane.getBorder()));
entrantPane.setMaximumSize(new Dimension(60,300));
// Initializes the ScrollPane for the timeList and adds the timeList to it.
nodeModel = new DefaultListModel();
nodeList = new JList(nodeModel);
nodeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
nodePane = new JScrollPane(nodeList);
nodePane.setMaximumSize(new Dimension(60, 300));
nodePane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createCompoundBorder
(BorderFactory.createTitledBorder("Nodes"),BorderFactory.createEmptyBorder(5,5,5,5)),nodePane.getBorder()));
// Structures the components in the frame using GridBagLayout.
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 2;
c.ipadx = 5;
c.insets = new Insets(10,10,10,10);
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(enterTime, c);
c.gridx = 2;
c.gridy = 0;
c.gridwidth = 2;
c.ipadx = 5;
c.insets = new Insets(10,10,10,10);
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(enterMed, c);
c.gridx = 0;
c.gridy = 1;
c.gridwidth = 2;
c.ipady = 100;
c.insets = new Insets(10,10,10,10);
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(entrantPane, c);
c.gridx = 2;
c.gridy = 1;
c.gridwidth = 2;
c.ipady = 100;
c.insets = new Insets(10,10,10,10);
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(nodePane, c);
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 1;
c.ipadx = 5;
c.ipady = 5;
c.insets = new Insets(10,10,10,10);
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(arrivalLabel, c);
c.gridx = 1;
c.gridy = 2;
c.gridwidth = 1;
c.ipadx = 5;
c.ipady = 5;
c.insets = new Insets(10,10,10,10);
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(arrival, c);
c.gridx = 2;
c.gridy = 2;
c.gridwidth = 1;
c.ipadx = 5;
c.ipady = 5;
c.insets = new Insets(10,10,10,10);
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(checkLabel, c);
c.gridx = 3;
c.gridy = 2;
c.gridwidth = 1;
c.ipadx = 5;
c.ipady = 5;
c.insets = new Insets(10,10,10,10);
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(check, c);
c.gridx = 0;
c.gridy = 3;
c.gridwidth = 1;
c.ipadx = 5;
c.ipady = 5;
c.insets = new Insets(10,10,10,10);
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(depLabel, c);
c.gridx = 1;
c.gridy = 3;
c.gridwidth = 1;
c.ipadx = 5;
c.ipady = 5;
c.insets = new Insets(10,10,10,10);
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(dep, c);
c.gridx = 2;
c.gridy = 3;
c.gridwidth = 1;
c.ipadx = 5;
c.ipady = 5;
c.insets = new Insets(10,10,10,10);
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(submit, c);
c.gridx = 3;
c.gridy = 3;
c.gridwidth = 1;
c.ipadx = 5;
c.ipady = 5;
c.insets = new Insets(10,10,10,10);
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(cancel, c);
c.gridx = 0;
c.gridy = 4;
c.gridwidth = 4;
c.ipadx = 20;
c.ipady = 30;
c.insets = new Insets(10,10,10,10);
c.fill = GridBagConstraints.HORIZONTAL;
panel.add(messageArea, c);
//Adds the panel to the frame and sets the components to fit according to the size of the frame.
add(panel, c);
pack();
setVisible(true);
}