• Post Reply Bookmark Topic Watch Topic
  • New Topic

JCheckBox label  RSS feed

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way to make the text next to my JCheckBox appear on the left side rather than the right side?
 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am also wondering how to make the checkbox appear with a white background, and a red 'check' when the user selects it. I tried doing a setBackground(), however, this is not what I want it to look like. I just want the inside of the box to be white, not the whole component.
Is this possible??
Thanks again!
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you might need to write your own ComboBoxUI or even your own LookAndFeel or (Metal)Theme respectively.
See the API of these classes and the swing tutorial for a start.
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for a quick hack of course:
look through the source code of JComboBox. I think it uses the MetalComboBoxIcon internally. With some copy paste you might scramble your own combobox together.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In answer to your first question...

there is the setHorizontalTextPosition( int ) method, which takes one of these values...

SwingConstants.RIGHT
SwingConstants.LEFT
SwingConstants.CENTER
SwingConstants.LEADING
SwingConstants.TRAILING

In answer to your second question...

You could do as Chantal suggested ( Well... replacing references to ComboBox to CheckBox... ) I think the name of the UI class for JCheckBox is BasicCheckBoxUI.

You could also just make two icons and make a special JToggleButton that switches between them...
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh, oh, thanks Nathan, I meant JCheckBox.
(Hey, they certainly are similar. Maybe Jennifer would want to change the look of her combo boxes as well?)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!