Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBox Problem  RSS feed

 
Stephan Bardubitzki
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I try to make the text field of a JComboBox transparent with this code:


but it doesn't do the Job.

I also would like to make the drop down list of the JComboBox transparent, but don't know how to retrieve the list object.

Any help is highly appreciated.

Stephan
 
thejaswini ramesh
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well textfield can be made transparent(also editable) by invoking the setEditable method...am also trying to make the dropdown list transparent.You could try this:


The problem with this is even the button on the combobox becomes white.I want the button to be visible in the default color and the textfield and dropdown list in white[like the one present on this very page ].Someone please let me know if its possible.

Thanks,
Thejaswini.

[ January 11, 2006: Message edited by: thejaswini ramesh ]
[ January 11, 2006: Message edited by: thejaswini ramesh ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I try to make the text field of a JComboBox transparent with this code:

try this

 
Stephan Bardubitzki
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Micheal,

this is doing the job:


I have the text field transparent, but unfortunately the button changed its L&F. Is there a way to avoid this?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is these lines that do most of the transparency
cbo.setOpaque(false);
((JTextField)cbo.getEditor().getEditorComponent()).setOpaque(false);

changing the UI to basic gets rid of the textfield border(?), so it appears 'seemless'.
actually, you only need to do this
cbo.setUI(new BasicComboBoxUI());

perhaps if you experimented with the textfield's border, you may get what
you're after
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see if this is any closer to what you want

 
Stephan Bardubitzki
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Michael!

Your code sample works very well for my use case.

Stephan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!