Re: Combobox how to disable edit but allow select
- From: "John_Woo" <john_woo@xxxxxxxxxx>
- Date: 28 Sep 2006 06:44:35 -0700
dnasmars@xxxxxxxxx wrote:
John_Woo a écrit :
Michael Rauscher wrote:try this
John_Woo schrieb:
Hi,
after setEditable(false) in a JComboBox, it can't allow to select a
item (display blank).
I'm wondering, how to disable the edit but with select function enable?
import javax.swing.*;
public class Test {
public static final void main( String args[] ) throws Exception {
JComboBox comboBox = new JComboBox(
new String[]{"1.", "2.", "3."} );
comboBox.setEditable( false );
JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
frame.setContentPane( comboBox );
frame.pack();
frame.setVisible( true );
}
}
Works for me.
Bye
Michael
Thanks lots, but my case
class MyComboBox extends JComboBox implements ActionListener
{
MyComboBox()
{
addItem("a");
addItem("b");
addItem("c");
setEditable( false );
addActionListener( this); //line A
}
}
without line A it works as yours, but with line A, it just couldn't
work (whenever select, it left it blank).
Can you fix it?
--
John
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.
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.
John
.
- Follow-Ups:
- Re: Combobox how to disable edit but allow select
- From: Michael Rauscher
- 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
- Combobox how to disable edit but allow select
- Prev by Date: Re: whats is PCDATA ?
- Next by Date: Paid participation in an open source project
- 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
|
|