Gradient background in dock station?

Hello guyz.

Is it possible to add gradient background to dock station?
How can I do that?

You like the movie “mission impossible”?

The framework uses many layers of JPanels and JComponents, accessing and modifying them directly may proof to be a lot of work (and not possible with the current version of the framework).

I suggest using the LookAndFeel to replace the PanelUI and ComponentUI of all Panels and Components of your application. Then each Component has to find out whether it belongs to some DockStation and paint its background accordingly.

[QUOTE=Beni]You like the movie „mission impossible“?

The framework uses many layers of JPanels and JComponents, accessing and modifying them directly may proof to be a lot of work (and not possible with the current version of the framework).

I suggest using the LookAndFeel to replace the PanelUI and ComponentUI of all Panels and Components of your application. Then each Component has to find out whether it belongs to some DockStation and paint its background accordingly.[/QUOTE]

Thanks for your idea. I’ve done.

Here’s the screenshot:

Nice :slight_smile:

Hi,

I’m trying to solve the same problem. Could you please share the code for you test application?

I’m used NimbusLookAndFeel.

  1. Extend NimbusLookAndFeel and set Panel.opaque, Viewport.opaque and RootPane.opaque properties to false to make panel, viewport and rootpane transparent.
public class MyLookAndFeel extends NimbusLookAndFeel {
    public MyLookAndFeel () {
        super();

        getDefaults().put("Panel.opaque", Boolean.FALSE);
        getDefaults().put("Viewport.opaque", Boolean.FALSE);
        getDefaults().put("RootPane.opaque", Boolean.FALSE);
    }
}
  1. Override JPanel paintComponent method.
protected void paintComponent(Graphics g) {
   if (!isOpaque()) {
       super.paintComponent(g);
       return;
   }

   // paint background
   int w = getWidth();
   int h = getHeight();

   // Paint a gradient from top to bottom
   GradientPaint gp = new GradientPaint(
           0, 0, new Color(87, 121, 240),
           0, h, new Color(225, 243, 244));

   Graphics2D g2d = (Graphics2D) g;
   g2d.setPaint(gp);
   g2d.fillRect(0, 0, w, h);

   setOpaque(false);
   super.paintComponent(g);
   setOpaque(true);
}
  1. Set the look and feel in event dispatch thread.
MyLookAndFeel lookAndFeel = new MyLookAndFeel ();
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
UIManager.setLookAndFeel(lookAndFeel);

JFrame frame = new JFrame("frame");

If someone need I can upload the full test source code.

Thanks very much for the quick response. I got it working. Cheers.