I want to change the selected icon for a JCheckbox to a different icon, let's say for example the disabled selected icon for a JCheckbox. How can I get the disabled selected icon from the UIManager?
I tried UIManager.getIcon("CheckBoxUI.disabledSelectedIcon"); Is that the wrong icon property name or is that just the wrong way to get to that resource?
Apparently there isn't one by default. At least, not when I'm trying to call it.
Just dumping the keys from UIManager.getLookAndFeelDefaults().keys() produces the following if the key contains CheckBox:
CheckBox.foreground
CheckBox.border
CheckBox.totalInsets
CheckBox.background
CheckBox.disabledText
CheckBox.margin
CheckBox.rollover
CheckBox.font
CheckBox.gradient
CheckBox.focus
CheckBox.icon
CheckBox.focusInputMap
After reading akf's answer, I started digging through the UIManager code in the plaf.synth packages and found calls that essentially delegate the null disableCheckedIcon to the look and feel classes to try to convert the standard .icon to a grayed version. So I ended up with this:
Icon checkedIcon = UIManager.getIcon("CheckBox.icon");
Icon dsiabledCheckedIcon =
UIManager.getLookAndFeel().
getDisabledSelectedIcon(new JCheckBox(), checkedIcon);
Looking through the code for AbstractButton, it appears that the disabledSelectedIcon is derived from the selectedIcon, unless it is specified on the AbstractButton (or JCheckBox in this case) through setDisabledSelectedIcon. With this being the case, calling UIManager.getIcon("...") will not return the object you are looking for.
EDIT:
Note that a JCheckBox has an icon field as defined in the AbstractButton API, just as a JButton can have an icon. It is an image that is displayed next to the text and is separate from the 'checked' or 'unchecked' box icon that you may be referring to.
The check/uncheck icon is handled by a single class, found with UIManager.getObject('CheckBox.icon'). It is a subclass Icon and handles both the painting of its checked and unchecked state. You can see examples of it in the various [L&F name]IconFactory classes.
Related
I have a java application which has JCheckBoxes used to show the state of an object.
These CheckBoxes cannot/shouldnt be changed by the user.
So, obviously, I did:
checkbox.setEnabled(false);
However, now the Tick/icon image is grayed out.
I want the disabled JCheckBox to look BETTER, like its enabled but dont allow the user to change its state.
How can I do that? How can I make the TICK image on the disabled CheckBox looks better (higher contrast) ?
I want the disabled JCheckBox to look BETTER, like its enabled but dont allow the user to change its state.
This says "readonly" JCheckBox to me. In this case, you'd need to supply a ButtonModel which stops the state from been changed. For example How to make read-only JCheckBox in Swing?
I want to actually change the tick image/color on the CheckBox
Then you need to use the JCheckBox#setSelectedIcon and JCheckBox#setIcon as well as the JCheckBox#setDisabledIcon and JCheckBox#getDisabledSelectedIcon methods to supply your own icons
I've created a CCombo object. I've added an AccessibilityControlListener and overridden the getRole(AccessibleControlEvent e) method. The code inside the method is
e.detail = ACC.ROLE_COMBOBOX;
But the screen reader(JAWS) still reads the CCombo as edit read only. But it should read combo box since i've overridden the default role. But it dosen't seem to work. Furthermore, the CCombo object doesn't even respond to the overridden accessiblitylistener or accessibilitycontrollistener methods.
(this is not exactly an answer, but the comment field ran out of space)
Other than most SWT widgets, CCombo isn't a native widget. Instead it is composed of other (native) widgets, namely a Text, a Button and a List. Apparently, not all accessibility events are overridden or redirected to the right widget.
The SWT Bugzilla lists several issues with CCombo and accessibility (search for 'ccombo accessibility'). Looking a the age and activity of the bugs it seems unlikely that they will be fixed anytime soon.
You might be better off using the (native) Combo widget if that's an option for you.
Depending on how desperate you need a fix, you could also write your own CCombo and fix the accessibility issues there. Of course only if all CCombos are created by your code.
Knowing the internal structure of the widget, you could also attach appropriate accessibility listeners to the respective children (Text, Button, List) if that's enough to fix your issues.
I´m new in creating GUI in Java, I would like to implement JComboBox (which uses GlazedLists), in my JFrame, which is in another class. Is it possible to call this JComboBox in my JFrame? I´m asking because I use NetBeans (some parts of code are forbidden to edit). Thanks
You can access the reference to the JComboBox like any other variable. The name of the combo boxes variable will depend if your reamed the object or not (you can do this from the form inspector, usually found under the projects window when in design mode)
While you can't modify the code in the protected blocks, you still effect he combo box (or any other component) within your code normally, just make sure initComponents has been called first
I need to make selection of text using mouse instead of ctrl+A
I tried:
sendAcceleratorKey(MouseEvent.BUTTON1, "");
but I don't know which argument could I set to say make a click with mouse and let the mouse enforced to select the text.
If the text is in a JTextComponent, selectAll() may be a suitable choice in your MouseListener.
Addendum: You may also be able to leverage the select-all Action, which is bound to control-A or meta-A by default on various platforms.
Your sscce may be helpful in deciding. There's a related example here.
Is there any way to include a Text Box inside a draw2d figure? (a code example would be nice)
Not easily, and if you're just using Draw2d without GEF, then I don't think it's possible.
With GEF, you can make use of a DirectEditManager in an Edit Part, and create an Edit Policy (extending DirectEditPolicy, installed with the key EditPolicy.DIRECT_EDIT_ROLE) to allow a direct edit to be performed on a figure.
You could create a figure which extends Label that is styled to look like a text box, and activate (by overriding performRequest in the Edit Part) editing upon selection.
This Schema Diagram example contains this type of functionality (and more importantly, the code!), although the figure used for edit (EditableLabel) isn't styled to look like a text box, and the activation itself is on double-click rather than selection.
It may point you in the right direction though.