1   package org.wcb.gui.component;
2   
3   import javax.swing.*;
4   import java.awt.*;
5   
6   /**
7    * <small>
8    * <p/>
9    * Copyright (C)  2006  wbogaardt.
10   * This library is free software; you can redistribute it and/or
11   * modify it under the terms of the GNU Lesser General Public
12   * License as published by the Free Software Foundation; either
13   * version 2.1 of the License, or (at your option) any later version.
14   * <p/>
15   * This library is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18   * Lesser General Public License for more details.
19   * <p/>
20   * You should have received a copy of the GNU Lesser General Public
21   * License along with this library; if not, write to the Free Software
22   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23   * <p/>
24   * $File:  $ <br>
25   * $Change:  $ submitted by $Author: wbogaardt $ at $DateTime: Nov 14, 2006 1:58:30 PM $ <br>
26   * </small>
27   *
28   * @author wbogaardt
29   *         paints a panel that has colors of every other line painted kind of a scan
30   * line effect.
31   */
32  
33  public class JScanLinePanel extends JPanel {
34  
35      private Color grad_even = new Color(0xf6f5f4); //new Color(0x024cc4);
36      private Color grad_odd = new Color(0xa7a5a3); //new Color(0xffffff);
37  
38  
39      public Color getGradEven() {
40          return grad_even;
41      }
42  
43      public void setGradEven(Color grad_even) {
44          this.grad_even = grad_even;
45      }
46  
47      public Color getGradOdd() {
48          return grad_odd;
49      }
50  
51      public void setGradOdd(Color grad_odd) {
52          this.grad_odd = grad_odd;
53      }
54  
55      protected void paintComponent(Graphics g) {
56          super.paintComponent(g);
57          Graphics2D g2 = (Graphics2D) g;
58          g2.setBackground(grad_odd);
59          for (int y = 0; y < getHeight(); y++) {
60              g2.setColor(grad_even);
61              g2.drawLine(0, y, getWidth(), y);
62              g2.drawLine(0, y + 1, getWidth(), y + 1);
63              y = y + 2;
64          }
65      }
66  
67      public static void main(String[] args) {
68          JFrame frame = new JFrame();
69          JScanLinePanel pane = new JScanLinePanel();
70          pane.setPreferredSize(new Dimension(200, 300));
71          frame.add(pane);
72          frame.setVisible(true);
73          frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
74      }
75  }