Java Nimbus Button.foreground not working - java

I am using the Nimbus LAF on my application and I want to change all buttons foreground colors. I do this setting:
UIManager.put("Button.foreground", Color.WHITE);
But this is not working. Maybe it is because I should only use the primary and secondary Nimbus colors? Could anyone help me please?
Thanks a lot.

simple way
1) you can set Color once by put value to UIManager, then will be valid for whole (for example JLabel) instance
2) dynamically set and override UIManager repeatedly
most complex way
3) create own UIManager, for example by aephyr
EDIT:
< to avoiding to create own Painters /> maybe correct way could be use non_buggy and todays Custom Look and Feel

Related

How can we merge elements from different look and feels?

I am a beginner in Java GUI, and I want to set a good looking look and feel; but the problem is that I don't like any of the look and feel completely. Everyone has some good and some bad styles. Being specific, I am using Nimbus look and feel, but I like the table and text area of liquid look and feel. I want to use Nimbus look and feel as default, but only use JTable and JTextArea of Liquid Look and feel. Is this possible?
Please answer using easy vocabulary, as I said I am a beginner.
ps: I use Netbeans.
You may be able to use the ad hoc approach shown here for JTree icons.
Left: com.apple.laf.AquaLookAndFeel
Right: javax.swing.plaf.metal.MetalLookAndFeel
Addendum: While not all combinations are compatible, you can examine the defined UIManager Defaults for keys common to both. A few JTable examples are shown here.

Changing colors of JButtons of LookAndFeel

I am working on an Java application, and I'm setting the LookAndFeel. Everything of the LAF I like except the default background color of the JButtons. What's the best way to set that (and other properties) after I set the look and feel? I don't want to have to create my own look and feel that extends it... would love to just be able to change it after the line I set the LAF...
Found it myself shortly afterwards.
UIManager.getDefaults().put("Button.background",new Color(0xFFFFFF));

Java/Swing Volume Slider

Part of my application has a media component, and I'm looking for a nice volume slider I can use rather than a JSlider which looks a bit ugly for this purpose (or specifically, an extended JSlider with custom visuals would be nice). I could write one, but I don't really want to reinvent the wheel.
In terms of "nice" volume sliders - I'm looking on the lines of something like VLC:
Is there a (free) component like this already out there that I'm missing?
Jasper Potts has a nice blog post about how you can skin the slider using Nimbus Look and Feel: Skinning a slider with Nimbus.
Here is how it looks like:
By following the blog post, it's not very hard to make your own custom look on the slider. You may also be interested in my answer about customizing the JScrollPane using Nimbus Look and Feel with a full code example.
Since you will want a mute operation if clicking on the speaker, I suggest that you implement your own JSlider and plug it in to the look-and-feel; however, I would also highly suggest that you reused the BoundedRangeModel that the JSlider implements.
Or, you could subclass a JPanel and package two widgets in it internally; however, this technique will require a mediator pattern to keep the two widget's displays in sync with the one shared BoundedRangeModel.
Look at the old Sun documentation about making custom widgets, and use the source code for JSlider as a starting point. It's not as hard as it may seem; however, it does take some time to get it "just right".

Is it possible to change the background of a jspinner using the nimbus laf?

I'm fairly confident that I have done my research before coming to you for help, but it's possible I have overlooked something.
I'm writing a java UI using the Nimbus l-a-f. I wish to change the background colour of a JSpinner on state-change, ie, when either the up or down button is pressed the background colour of the textfield within the jspinner changes colour to signify that the value has been altered.
I am aware this is possible using OTHER lookandfeels but not as easy with Nimbus, eg:
((JSpinner.NumberEditor)jSpinner1.getEditor()).getTextField().setBackground(color.yellow);
I have also looked into actually changing the colour theme of the UI manager, but I only want to change the colour when an action occurs, not just overall by default.
here or here
Is this at all possible and where do I start?
Failing this, I was hoping to just change a button's colour:
jButton.setBackground(Color.yellow);
This is easy enough but since the default colour is a painted gradient, how do I change it back to that?
Really hope someone out there knows or can help.
Much appreciated in advance!
Yes, it is possible. See this example (i.e. SpinnerDemo4) from The Java Tutorials for more detail. And yes, I did set the LaF to Nimbus when testing the code therein.

getting TableCellEditor colors to match match look and feel

So I have custom CellEditors and CellRenderers and although I am doing
component.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
component.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
component.setOpaque(true);
in my getTableCellRendererCompoent, the colors only match on every OTHER row, since most of hte look and feels I've tried seem to alternate them. How can I pull the color values in a way that they'll match whatever the rest of the table looks like? I'd also really like to be able to make nice borders to match the renderers descended from DefaultTableCellRenderer.
I've tried to dissect the DefaultTableCellRenderer, and I got lost trying to track down this UI object. Do I just need the right properties to pull from the UIManager? A lead in the right direction will be much appreciated.
Thanks all, this site rocks.
Joshua
Yes, you should use the Swing palette colors. For example:
final Color tableBackground = javax.swing.UIManager.getDefaults().getColor("Table.background");
Here's the color key values for tables:
Table.background Table.dropLineColor
Table.dropLineShortColor
Table.focusCellBackground
Table.focusCellForeground
Table.foreground Table.gridColor
Table.selectionBackground
Table.selectionForeground
Table.sortIconColor
TableHeader.background
TableHeader.focusCellBackground
TableHeader.foreground
Alternatively, you could also use the system colors. For example:
Normal background: SystemColor.window
Selected background: SystemColor.textHighlight
Normal foreground: SystemColor.text
Selected foreground: SystemColor.textText

Categories

Resources