【发布时间】:2014-06-30 22:37:53
【问题描述】:
当用户双击该项目时,我试图从JList 填充JTextArea。我不完全确定如何做到这一点,这是我目前所拥有的。
// Create Top Right JPanel and JList
String[] listB = { "Some content on the right panel", "More content", "Some more content", "More and more content", "More and more content", "More and more content",
"More and more content", "More and more content", "More and more content", "More and more content", "More and more content", "More and more content", "More and more content", "More and more content",
"More and more content" };
final JList listBottom = new JList(listB);
listBottom.setVisibleRowCount(12);
JScrollPane scrollPaneB = new JScrollPane(listBottom);
panelBottom.add(scrollPaneB);
scrollPaneB.setViewportView(listBottom);
scrollPaneB.setBorder(BorderFactory.createTitledBorder("Bottom Panel"));
scrollPaneB.setVisible(true);
//listBottom.setVisible(true);
listBottom.setBorder(BorderFactory.createLoweredBevelBorder());
// Create Top Right Action Listener
listBottom.addListSelectionListener(new ListSelectionListener(){
@Override
public void valueChanged(ListSelectionEvent arg0) {
Selection selectionB = (Selection)listBottom.getSelectedValue();
textField.setText(selectionB.getContents());
}
});
【问题讨论】:
-
我很好奇您是如何实现 Enter 键功能的?
标签: java swing mouseevent jlist