| Author |
please someone help
|
john mattucci
Ranch Hand
Joined: Nov 03, 2000
Posts: 331
|
|
Thank u in advance for whomever will take the time to help me My problem is as follows. I have a JComboBox with a number of choices; and also a JButton which allows the user to clear his choice just made. So for example, the user picked the 2nd item on the list and he wishes to clear it he presses clear. The problem is this I wish to fire an actionEvent only when an item is picked not when clear is pressed. Because the way I have written the code when clear is pressed the first item in the JComboBox is picked which is blank, and this fires an actionEvent which I dont want to happen. How do I stop it? I hope this is clear....
|
 |
ravindran shanmugam
Greenhorn
Joined: Aug 30, 2001
Posts: 15
|
|
import javax.swing.*; import java.awt.event.*; import javax.swing.event.*; import java.awt.*; public class Mycombo extends JFrame { public Mycombo() { JButton btnClear = new JButton("Clear"); final JComboBox cmbSelect = new JComboBox(); cmbSelect.addItem(""); cmbSelect.addItem("sdfw"); cmbSelect.addItem("mnbj"); cmbSelect.addItem("qerre"); cmbSelect.setEditable(true) ; JPanel contentPane = new JPanel(); contentPane.setLayout(new BorderLayout()); contentPane.setPreferredSize(new Dimension(400, 150)); contentPane.add(cmbSelect, BorderLayout.CENTER); contentPane.add(btnClear, BorderLayout.SOUTH); setContentPane(contentPane); btnClear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cmbSelect.setSelectedItem(""); System.out.println("Selected value is "+ (cmbSelect.getSelectedItem()).toString()+ "edsrtger"); } }); } public static void main(String[] args) { JFrame frame = new Mycombo(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.pack(); frame.setVisible(true); } }
|
 |
 |
|
|
subject: please someone help
|
|
|