tags:

views:

176

answers:

1

How to adding new colors to our gradient panel in java?

+1  A: 

hi bro extend your panel from JPanel and override it's paintComponent like this.

    @Override
protected void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
// Creates a two-stops gradient
GradientPaint p;
p = new GradientPaint(0, 0, new Color(0xFFFFFF),
0, getHeight(), new Color(0xC8D2DE));
// Saves the state
Paint oldPaint = g2.getPaint();
// Paints the background
g2.setPaint(p);
g2.fillRect(0, 0, getWidth(), getHeight());
// Restores the state
g2.setPaint(oldPaint);
// Paints borders, text...
super.paintComponent(g);
}
}

and you see the color object you can change existing color...

and i advise you to read

Filthy Rich Clients

and get this book from somewhere.it has more usefull information which you can may use of learn.

ibrahimyilmaz
You might want to add a link to where you copied this from: `DepthButton` at http://www.java2s.com/Code/Java/2D-Graphics-GUI/TwoStopsGradient.htm ?
Peter Lang
yes you are right
ibrahimyilmaz
See also http://filthyrichclients.org/
trashgod