private void channelItemsMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if(channelItems.getSelectedIndex()>=0)
{
JPanel p1=new JPanel();
JLabel label = new JLabel("Enter your username below", SwingConstants.CENTER);
p1.add(label);
add(p1);
}
}
答案 0 :(得分:1)
您需要双击MouseListener
,否则每次点击鼠标都会打开对话框。
ListSelectionModel listSelectionModel..
JList list=new JList(listSelectionModel);
list.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent evt) {
if (evt.getClickCount() == 2) {
//...Show the JDialog or JOptionPane here, not JPanel.
String name=JOptoinPane.showInputDialog(null, "Enter your username");
}
}
});
有关详情,请仔细阅读tutorial。
答案 1 :(得分:0)
简单地说:
actionMethod(...){
currentPanel.dispose();
newPanel.setVisible(true);
}