- 397 名前:デフォルトの名無しさん mailto:sage [04/01/02 22:46]
- JComboBoxについて質問します。以下のプログラムを実行し、コン
ボボックスのhogeを編集した後、ボタンを押すとhogeが出力されま す。もう一度ボタンを押すと編集されたテキストが出力されます。 一度押すだけで、編集したテキストを表示させるにはどうすればい いでしょうか。 import javax.swing.*;import java.awt.*;import java.awt.event.*; public class ComboBox implements ActionListener { JComboBox box; public ComboBox() { String[] patternExamples = { "hoge" }; box = new JComboBox(patternExamples); box.setEditable(true); JButton button = new JButton("hoge"); button.addActionListener(this); JFrame frame = new JFrame(); frame.getContentPane().setLayout(new FlowLayout()); frame.getContentPane().add(box); frame.getContentPane().add(button); frame.pack(); frame.show(); } public void actionPerformed(ActionEvent e) { System.out.println(box.getSelectedItem()); } public static void main(String[] args) { new ComboBox(); } }
|

|