File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT / JFace and the fly likes please someone help Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "please someone help" Watch "please someone help" New topic
Author

please someone help

john mattucci
Ranch Hand

Joined: Nov 03, 2000
Posts: 329
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
 
Threads others viewed
urgent please help
Having problem.. pls help..! Ugently..
JComboBox focus
KeyEvent - Keypress
JComboBox Mystery!
Two Laptop Bag

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture