5YrsLaterDBA
5YrsLaterDBA

Reputation: 34780

how to get the default color when draw a line for JSeparator

I override the paintComponent(Graphics g) method of the JSeparator to get a thicker line and different color when needed.

But I cannot get its original default color. The color changed to black if the color is null in the following code, which I don't like it in my case.

                int width = this.getSize().width;
                Graphics2D g2 = (Graphics2D) g;
                if (thickness > 0)
                {
                    g2.setStroke(new BasicStroke(thickness));
                }
                if (color != null)
                {
                    g2.setColor(color);
                }
                g2.drawLine(startPos, 0, width - endPos, 0); 

The original default color is not black. You can see this from the attached screen shot. The thinner and longer line is the original separator drawn by the call to super.paintComponent(g), The thicker and shorter one is drawn by above code when color is null.

So how can I get the original default color? I tried the color from getForeground(), getBackground() and getColor() call. But none is the original default color.

enter image description here

Upvotes: 0

Views: 134

Answers (1)

camickr
camickr

Reputation: 324128

You might be able to use the UIManager to get the default color.

Check out UIManager Defaults for a list of default properties of Swing components

Upvotes: 1

Related Questions