• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JCheckBox label

 
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?)
reply
    Bookmark Topic Watch Topic
  • New Topic