I'm creating an AbstractColorChooserPanel for recent colours (in a 4 * 4 grid) and while setting the background colour for the recent colours it only appears as a border to the button instead of filling it.
According to this the code below should work:
button.setBackground(Color.RED);
button.setOpaque(true);
Ive also tried adding
button.setBorderPainted(false);
but all that displays is a grey (standard colour) button with a red border.
I have tried putting the code on a button outside the JColorChooser and received the same effect. example
How do I make it so the entire button is filled with the red colour instead of just the border?
EDIT: The problem turned out to be the UIManager (default system look and feel)
To solve this I modified the code used in this solution.
Try adding this :
button.setContentAreaFilled( false );
Related
Recently I noticed that the buttons in my application are not rendering correctly.
In this example, the button has gray border. The problem is that the background of the button is bigger than the bounds of the border.
How do I make the border appear just outside the bounds of the background?
Okay, I looked through my whole project and changed the CSS all over the places... Then I realized something - that extra space that looks like the button's background fill, is not actually that.
I added this to my stylesheet:
.root
{
-fx-shadow-highlight-color: red;
}
And surprisingly, this is how it looks like now:
So it's actually a shadow for the button. Most of the time it's not obvious because this is how Modena.css defines it:
-fx-shadow-highlight-color: ladder(
-fx-background,
rgba(255,255,255,0.07) 0%,
rgba(255,255,255,0.07) 20%,
rgba(255,255,255,0.07) 70%,
rgba(255,255,255,0.7) 90%,
rgba(255,255,255,0.75) 100%
);
So if a custom background color is specified on any of the button's ancestor nodes, then this shadow would visually look odd.
I have a org.eclipse.swt.widgets.Text box.
private org.eclipse.swt.widgets.Text textBox = new Text(parent , SWT.BORDER)
how do i set the border color for this text box? Setting background can be done using setBackground, but i did not find any option for border!
I found this:
http://www.java-tips.org/other-api-tips-100035/168-eclipse/1570-how-to-add-colored-border-around-the-text-widgets.html
Now how do i notify the paintListener?
Basically upon a condition border should change to red!
You just call redraw() when you what to toggle between clean and red. The paint listener will be called automatically.
i try to set Background color of jbutton, but doesn't work? Look at image. Why doesnt work? How to fix?
I want red background :-)
save_button.setForeground(Color.red);
save_button.setBackground(Color.red);
close_button.setForeground(Color.red);
close_button.setBackground(Color.red);
Add to the code for both buttons :
save_button.setOpaque(true);
It should work, if not try disabling the border color
I'm writing checkers. So, every cell is JButton, it has image (ImageIcon).
I want JButton that has background image and backlighting (for example, blue of red), because I want to show user available turns. Is it possible?
Now if I create new JButton(Icon icon) and then setBackground(Color.BLUE);
background is ignored.
You should set its border color to BLUE or RED (I believe this is what you are looking for as an answer)
Try this statement:
chessButton.setBorder(BorderFactory.createLineBorder(Color.GREEN));
Painting JButton's border is not effected by image icon, therefore if you want to create a highlight effect and set border's color you should use BorderFactory. You can also have various effects for the border through BorderFactory
If you want complete background highlighted or some special effect then have two separate image of each cell i.e. one normal image and one highlighted image. When you want to show user its available turns, simply update the respective cells with their corresponding highlighted image
I have around 50 buttons .some are green(selected),some are grey(deselected).
If i press the green buttons ,they should change their colour to red and back to green on pressing again.
If i press the grey buttons ,they should change their colour to green and back to grey on pressing again.
All buttons have some text in black.On pressing the buttons,the colour of the text remains unchanged.
Suggest a solution or tutorial for same...
Don't use a JButton for this but instead use a JToggleButton. Consider giving them ImageIcons for their state.