Re: disabling JComboBox options
From: VisionSet (spam_at_ntlworld.com)
Date: 06/30/04
- Next message: Roedy Green: "Re: How to manipulate IP addresses"
- Previous message: Roedy Green: "Re: Need to display an HTML page from background thread"
- In reply to: hilz: "Re: disabling JComboBox options"
- Next in thread: hilz: "Re: disabling JComboBox options"
- Reply: hilz: "Re: disabling JComboBox options"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 30 Jun 2004 12:12:01 +0100
"hilz" <hilz@noway.com> wrote in message
news:gcrEc.16524$x9.13609@nwrddc02.gnilink.net...
> Mike:
> thank you for the idea.
> it did not really work very well, maybe i am missing something.
> the setEnabled(false) makes the list cell disabled (the color of the text
> is greyed), but it still can be selected.
> what do i need to prevent it from being selectable?
> is there something i am missing here?
>
> here is the code of the list cell rendere i implemented:
>
> class RegionListCellRenderer extends JLabel implements ListCellRenderer {
> public RegionListCellRenderer() {
> setOpaque(true);
> }
> public Component getListCellRendererComponent(
> JList list,
> Object value,
> int index,
> boolean isSelected,
> boolean cellHasFocus){
> boolean isCellSelectable=false;
>
> if(some condition here){
> isCellSelectable=false;
> }
> else{
> isCellSelectable=true;
> }
>
> setText(value.toString());
>
> this.setEnabled(isCellSelectable);
>
> if (isSelected && isCellSelectable) {
> setBackground(list.getSelectionBackground());
> setForeground(list.getSelectionForeground());
> } else {
> setBackground(list.getBackground());
> setForeground(list.getForeground());
> }
> return this;
> }
> }
>
If you do something like this as well:
static class MyComboBox extends JComboBox {
public MyComboBox(Object[] objs) {
super(objs);
}
public void setSelectedIndex(int i) {
if(i != 2) super.setSelectedIndex(i);
}
}
Should achieve the desired affect.
There is probably a better way.
-- Mike W
- Next message: Roedy Green: "Re: How to manipulate IP addresses"
- Previous message: Roedy Green: "Re: Need to display an HTML page from background thread"
- In reply to: hilz: "Re: disabling JComboBox options"
- Next in thread: hilz: "Re: disabling JComboBox options"
- Reply: hilz: "Re: disabling JComboBox options"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|