我有以下代码来跟踪用户在表格中选择的内容,在用户选择聊天对话后,我想隐藏JPanel
包含表格的内容并显示JPanel
包含聊天对话的内容。请参阅我当前的代码以执行此操作:
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
JTable target = (JTable) e.getSource();
int row = target.getSelectedRow();
int column = target.getSelectedColumn();
// loop through all elements in the table
for (int i = 0; i < listmodel.size(); i++) {
// get the table item associated with the current element
final Object object = listmodel.get(i);
if (object instanceof ListItem) {
ListItem listitem = (ListItem) object;
if (table.getValueAt(table.getSelectedRow(), 0).toString() == listitem.getText()) {
// Show the chat conversation (this is where the GUI for some reason does not fully load)
SwingUtilities.invokeLater(new Runnable() {
public void run() {
pnlMainTableWrapper.setVisible(false); // Contains the table
pnlChatMsgs.setVisible(true);
pnlSendMsg.setVisible(true);
pnlRight.setVisible(true);
pnlChatMsgs.validate();
pnlChatMsgs.repaint();
}
});
}
}
}
}
}
});
由于某些奇怪的原因,并非所有 GUI 组件JPanel
pnlChatMsgs
都被加载,这些组件只是白色的。
任何想法是什么导致了这种行为?