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.
Related
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 );
I have a series of column labels that scrolls independently from the data that is displayed in a matrix below. I can make the whole scrollbar transparent except on hover. The labels are right up against the data, which I like, however, upon hover, unless I shift the vertical scroll (which I'd rather not do), the scrollbar obscures the beginning of all the labels.
I would like to set the background of the scrollbar as transparent so that only the "grabber" (or whatever it's called) is the only thing that is drawn. (It will obscure the beginning of the labels it is over, but would be a lot less so.)
Is there any way to do that? Here is what I tried:
Color bg = new Color(255,255,255,0);
colLabelScroll.setBackground(bg);
This does not seem to make the background of the scrollbar transparent.
What I'm shooting for is like how the iPhone's scrollbar grabber hovers over info in some apps. Is that even possible with JScrollBars?
Transparent JScrollBar can do it, but consider this: if column labels are related to the data and you can scroll them independently, beginner users may not understand what is going on and associate column labels with whatever is visually aligned beneath it. Either you will need some sort of visual indicator that makes it clear that the labels are disconnected from the data, or you should change the way labels are scrolled that never leaves them statically in 1 place.
Here's how I ended up making the relationship between the labels and the data clearer:
Instead of allowing the user to independently and intentionally scroll the labels, I decided to control the label scroll position via mouse hover. This eliminates the need for the obtrusive scrollbar.
I created a scroll-bar-like indicator that shows the portion of the data the labels represent.
I highlighted the currently hovered label that corresponds to the data below it, i.e. the only label that is ever correctly aligned with the data is the one that is under (or directly above) the cursor.
When the mouse is not hovered over (or dragging from) the column labels, do not display any labels. This helps prevent invalid label/data associations by the user.
A few nuanced notes: Implementing your own scrollbar-like indicator is somewhat involved, especially if your labels are painted and then rotated, because the paint position of 0 is at the bottom of the pane, yet the vertical scroll position of the pane is at the top. You will have to track the vertical scroll position to be able to recover it again when the cursor returns since you are blanking the labels on mouse out.
When developing a plugin for IntelliJ, I accomplished it with:
scrollPane.getVerticalScrollBar().setUI(ButtonlessScrollBarUI.createTransparent());
It takes advantage of the the:
ButtonlessScrollBarUI.createTransparent()
method, which is an IntelliJ specific method. However, if you can find a ScrollBarUI which has a transparent background, you can use the same trick.
Since I got a bit lost myself at first after reading #hepcat72's answer I'm posting a little explanation about the BasicScrollBarUI class:
JScrollBar scrollbar = scrollPaneConversation.getVerticalScrollBar();
scrollbar.setUI(new BasicScrollBarUI(){
// This function returns a JButton to be used as the increase button
// You could create your own customized button or return an empty(invisible) button
#Override
protected JButton createIncreaseButton(int orientation){
}
// Same as above for decrease button
#Override
protected JButton createDecreaseButton(int orientation){
}
// This function paints the "track" a.k.a the background of the scrollbar
// If you want no background just return from this function without doing anything
// If you want a custom background you can paint the 'Graphics g' object as you like
#Override
protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds)
{
}
// This function paints the "thumb" a.k.a the thingy that you drag up and down
// You can override this function to paint it as you like
#Override
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
{
}
});
Refer to the Transparent JScrollBar link posted by #hepcat72 for hints about what to do exactly in these functions.
When I use a HTMLComponent in LWUIT 1.5, it seems that the background is defaulted to white.
How do I make it transparent, or at least a background color that fills the entire screen?
I have tried the following:
.getStyle.setBgTransparency(0);
.getUnselectedStyle().setBgTansparency(0);
.getSelectedStyle().setBgTransparency(0);
.getStyle.setBgColor(0xff0000);
.getUnselectedStyle().setBgColor(0xff0000);
.getSelectedStyle().setBgColor(0xff0000);
All of the above are ignored.
I have also tried putting a color in the body:
.setBodyText("<div style='background: #ff0000'>Some text</div>");
.setBodyText("<body style='background: #ff0000'>Some text</body>");
.setBodyText("<body bgcolor='#ff0000'>Some text</body");
But that only puts the background color behind the text and does not fill the entire screen in height.
I have also tried putting the component in CENTER of a BorderLayout to make it fill the entire screen. Still no go.
Best would be if I can just make the background in the HTMLComponent transparent, so that I can constroll the background from the container component. Is this possible?
I managed to put a full screen background color by putting the HTMLComponent CENTER in a BorderLayout and then use this:
.setHTML("<html><body bgcolor='#eeee00'>This is some text</body></html>", "UTF-8", "", true);
I'm working on a PI approximation(using the infinite series) GUI, and I've run into a strange problem. In the JavaFX8 Scene Builder I set the background color to -fx-background-color: black; but when I start the program, the background is still white. The strange thing I've noticed is that the outline of the TextArea has turned black though. I've already checked for contradicting code that turns the background white again, but since I just started there can't be any. Stranger yet, the TextArea appears black in the preview of the program in the scene builder. The node graph can be seen in the first picture on the left.
EDIT:
FXML(In this text file, I couldn't figure out how to post the code. I tried the blockquote, posting it normally, and trying the code literal tags): https://www.dropbox.com/s/4ic6n1vbsqqu7pg/FXML.txt
Text Area In Scene Builder:
Text Area Running:
Sorry, a couple of years late..
.text-area .content
{
-fx-background-color: black;
}
I have an application that uses a JLabel and a JPanel. These components have a MatteBorder. When the components are created, the border is the default. When I click on the components, I set the border to a different thickness to make a select appearance. The problem comes when I want to unselect and I set the border to another thickness. This time the border is not modified and looks the same.
I'm not seeing what the problem is, because the first modification of the border thickness works fine.
Although this might be a hacky approach, try to repaint() the view, sometimes it just glitches.
I read this:
http://docs.oracle.com/javase/tutorial/uiswing/components/border.html
when working on my program.