Re: Combobox how to disable edit but allow select
- From: Michael Rauscher <michlmann@xxxxxx>
- Date: Thu, 28 Sep 2006 16:35:48 +0200
John_Woo schrieb:
dnasmars@xxxxxxxxx wrote:try this
public class MyComboBox extends JComboBox implements ActionListener {
public MyComboBox() {
addItem("a");
addItem("b");
addItem("c");
setEditable( false );
addActionListener( this); //line A
}
public void actionPerformed(ActionEvent e) {
System.out.println(" this is ugly ");
this.setForeground(Color.white);
}
}
I hope this helps
That's it! Thank you.
Color.black is better.
I don't know what you're doing but I know it must be something strange ;)
Michael's example (using an static inner class ) is fine, just didn't
understand why for standalone class, we have to explixitly set the
foreend color.
You do *not* need to. It doesn't make any difference if one uses a static inner class or a top level class:
import java.awt.event.*;
import javax.swing.*;
class MyComboBox extends JComboBox implements ActionListener {
public void actionPerformed( ActionEvent e ) {
System.out.println( "Action" );
}
public MyComboBox() {
addItem("a");
addItem("b");
addItem("c");
setEditable( false );
addActionListener( this );
}
}
public class Test {
public static final void main( String args[] ) throws Exception {
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
frame.setContentPane( new MyComboBox() );
frame.pack();
frame.setVisible( true );
}
}
Again, post an SSCCE of the problem.
Bye
Michael
.
- Follow-Ups:
- Re: Combobox how to disable edit but allow select
- From: John_Woo
- Re: Combobox how to disable edit but allow select
- References:
- Combobox how to disable edit but allow select
- From: John_Woo
- Re: Combobox how to disable edit but allow select
- From: Michael Rauscher
- Re: Combobox how to disable edit but allow select
- From: John_Woo
- Re: Combobox how to disable edit but allow select
- From: dnasmars
- Re: Combobox how to disable edit but allow select
- From: John_Woo
- Combobox how to disable edit but allow select
- Prev by Date: Re: How to solve the error "The local variable may not have been instantiated"?
- Next by Date: Re: Combobox how to disable edit but allow select
- Previous by thread: Re: Combobox how to disable edit but allow select
- Next by thread: Re: Combobox how to disable edit but allow select
- Index(es):
Relevant Pages
|
|