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
2010-02-22 08:05:07
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
2010-02-22 08:26:37
yes you are right
ibrahimyilmaz
2010-02-22 09:23:33
See also http://filthyrichclients.org/
trashgod
2010-02-22 13:24:54