How To GUI Form Gradient Background

Answered

Hi, I am a beginner on the Intellij Idea GUI Form. And I don't know how to set a gradient background to the form. Can someone help me? Thanks.

0
1 comment

You can't do it using UI Designer only.

But you can enable "Custom Create" property on a component and create panel with gradient manually in `createUIComponents()` method.
Ex: by overriding `protected void paintComponent(Graphics g)` and using `com.intellij.util.ui.UIUtil#getGradientPaint` there.
Smth like

@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
g2d.setPaint(UIUtil.getGradientPaint(0, 0, JBColor.RED, 0, getHeight(), JBColor.BLUE));
g2d.fillRect(0, 0, getWidth(), getHeight());
}

It uses plain Swing rendering, so there are should be plenty of samples on the web.

0

Please sign in to leave a comment.