Search code examples
javaswingjcheckbox

Create a JCheckBox with text as columnName but value as "schema.table.columnname"


I have a JCheckBox, where I need the value different from the Text displayed as processing needs some other name and the name to be displayed is a shorter name.

The only method I saw for JCheckBox is setText("Text") which just handles the display part.


Solution

  • A JCheckBox has a value of boolean and can display any String.

    Its value (which is its selected state) can be set/get using the isSelected() and setSelected() methods.

    Its displayed text can be set/get using the getText() and setText() methods.

    If you want to store another String value for it, you can use its getName() and setName() methods.

    If you need to store more values in the component and/or not just Strings, take a look at the putClientProperty() and getClientProperty() methods. Using these you can store any values associated with keys (provided by you):

    The get/putClientProperty methods provide access to a small per-instance hashtable.