1
我基本上要做出JList
(whatToSearch)滾下來,或者乾脆顯示其內容,以供選擇,一旦JButton
(popDownButton)被點擊。單擊JButton時,JList是否會滾降? JAVA
//SEARCH OPTIONS
popDownButton = new JButton(new ImageIcon(new ImageIcon("downArrow.png").getImage().getScaledInstance(20, 20, Image.SCALE_DEFAULT)));
whatToSearch = new JList(elementsToSearch);
whatToSearch.setVisibleRowCount(3);
whatToSearch.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scroll = new JScrollPane(whatToSearch);
popDownButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(null, scroll.getViewport());
}
});
add(popDownButton);
這段代碼的工作,但我正在尋找在同一界面中顯示的JList
的內容,旁邊的按鈕,而不是在另一個彈出界面。
它沒有工作,我很害怕,當我點擊按鈕時,沒有任何反應 –