我正在尝试在JTabbedPane中创建一系列面板,为用户显示一段信息。现在,我试图获取它,以便在单击编辑按钮后面板将刷新。此按钮将您带到另一个菜单,您可以在其中调整任何字段,然后返回选项卡式窗格。不幸的是,当对象通过使用上述菜单进行更改时,窗格并未正确反映这些更改。做的是使第一个面板和所有标签不可点击,并且似乎使用新信息将新面板添加到前一个面板的底部。这在repaint()期间发生,因为之前它根本不会改变。
JPanel leftPanel = new JPanel();
JPanel buttons = new JPanel();
JPanel title = new JPanel();
LayoutManager singleLine = new GridLayout(0,2);
leftPanel.setLayout(singleLine);
buttons.setLayout(new FlowLayout());
JLabel header = new JLabel("Basic Student Information");
title.add(header);
JLabel StreetLabel = new JLabel("First Name: "); //Creates all Labels
JLabel LNLabel = new JLabel("Last Name: ");
JLabel IDLabel = new JLabel("Student ID: ");
JLabel GPALabel =new JLabel("GPA: ");
JLabel StreetInfo = new JLabel(selectedStudent.getFirstName().toString());
JLabel LNInfo = new JLabel(selectedStudent.getLastName().toString());
JLabel IDInfo = new JLabel(selectedStudent.getID().toString());
JLabel GPAInfo = new JLabel(selectedStudent.getGpa().toString());
leftPanel.add(StreetLabel);
leftPanel.add(StreetInfo);
leftPanel.add(LNLabel);
leftPanel.add(LNInfo);
leftPanel.add(IDLabel);
leftPanel.add(IDInfo);
leftPanel.add(GPALabel);
leftPanel.add(GPAInfo);
StreetLabel.setHorizontalAlignment(JLabel.LEFT);
LNLabel.setHorizontalAlignment(JLabel.LEFT);
IDLabel.setHorizontalAlignment(JLabel.LEFT);
GPALabel.setHorizontalAlignment(JLabel.LEFT);
JButton edit = new JButton("Edit");
JButton close = new JButton("Close");
buttons.add(edit);
buttons.add(close);
basicInfoTab.add(title, BorderLayout.NORTH);
basicInfoTab.add(leftPanel, BorderLayout.CENTER);
basicInfoTab.add(buttons, BorderLayout.SOUTH);
edit.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent event){
readMenu.setVisible(false);
generalInfo();
}
});
close.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent event){
if(JOptionPane.showConfirmDialog(null, "Do you wish to exit this student's record?") == JOptionPane.OK_OPTION){
readMenu.setVisible(false);
HomeScreen();
}
}
});
非常感谢任何有助于成功刷新的帮助。