New Post

[Java] [Swing] [Netbeans] [ Custom Palette ] jPanel Gradient Background





  1. import java.awt.Color;  
  2. import java.awt.Component;  
  3. import java.awt.Dimension;  
  4. import java.awt.GradientPaint;  
  5. import java.awt.Graphics;  
  6. import java.awt.Graphics2D;  
  7. import java.awt.RenderingHints;  
  8. import java.awt.event.MouseMotionListener;  
  9. import javax.swing.JCheckBox;  
  10. import javax.swing.JFormattedTextField;  
  11. import javax.swing.JLabel;  
  12. import javax.swing.JPanel;  
  13. import javax.swing.JPasswordField;  
  14. import javax.swing.JRadioButton;  
  15. import javax.swing.JTextField;  
  16. import javax.swing.JToolBar;  
  17. /** 
  18.  * 
  19.  * @author Andi.irah 
  20.  */  
  21.   
  22. public class AeGradientPanel  
  23.   extends JPanel  
  24. {  
  25.   public Color AeStartColor = Color.MAGENTA;  
  26.   public Color AeEndColor = Color.BLUE;  
  27.   public boolean AeTranspControls = true;  
  28.   public int AeGradientFocus = 500;  
  29.   public int AeBorderRadius = 10;  
  30.   public boolean AeFillBackground = true;  
  31.     
  32.   public boolean isAeFillBackground()  
  33.   {  
  34.     return this.AeFillBackground;  
  35.   }  
  36.     
  37.   public void setAeFillBackground(boolean AeFillBackground)  
  38.   {  
  39.     this.AeFillBackground = AeFillBackground;  
  40.   }  
  41.     
  42.   public int getAeBorderRadius()  
  43.   {  
  44.     return this.AeBorderRadius;  
  45.   }  
  46.     
  47.   public void setAeBorderRadius(int AeBorderRadius)  
  48.   {  
  49.     this.AeBorderRadius = AeBorderRadius;  
  50.   }  
  51.     
  52.   public Color getAeStartColor()  
  53.   {  
  54.     return this.AeStartColor;  
  55.   }  
  56.     
  57.   public void setAeStartColor(Color AeStartColor)  
  58.   {  
  59.     this.AeStartColor = AeStartColor;  
  60.   }  
  61.     
  62.   public Color getAeEndColor()  
  63.   {  
  64.     return this.AeEndColor;  
  65.   }  
  66.     
  67.   public void setAeEndColor(Color AeEndColor)  
  68.   {  
  69.     this.AeEndColor = AeEndColor;  
  70.   }  
  71.     
  72.   public boolean isAeTranspControls()  
  73.   {  
  74.     return this.AeTranspControls;  
  75.   }  
  76.     
  77.   public void setAeTranspControls(boolean AeTranspControls)  
  78.   {  
  79.     this.AeTranspControls = AeTranspControls;  
  80.   }  
  81.     
  82.   public int getAeGradientFocus()  
  83.   {  
  84.     return this.AeGradientFocus;  
  85.   }  
  86.     
  87.   public void setAeGradientFocus(int AeGradientFocus)  
  88.   {  
  89.     this.AeGradientFocus = AeGradientFocus;  
  90.   }  
  91.     
  92.   public AeGradientPanel()  
  93.   {  
  94.     setPreferredSize(new Dimension(380280));  
  95.     if (this.AeTranspControls) {  
  96.       setBg(true);  
  97.     } else {  
  98.       setBg(false);  
  99.     }  
  100.   }  
  101.     
  102.   public synchronized void addMouseMotionListener(MouseMotionListener l)  
  103.   {  
  104.     super.addMouseMotionListener(l);  
  105.   }  
  106.     
  107.   protected void paintComponent(Graphics g)  
  108.   {  
  109.     super.paintComponent(g);  
  110.     Graphics2D g2d = (Graphics2D)g;  
  111.     g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);  
  112.     g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);  
  113.       
  114.     int w = getWidth();  
  115.     int h = getHeight();  
  116.     Dimension arcs = new Dimension(this.AeBorderRadius, this.AeBorderRadius);  
  117.       
  118.     GradientPaint gp = new GradientPaint(0.0F, 0.0F, this.AeStartColor, this.AeGradientFocus, h, this.AeEndColor);  
  119.       
  120.     g2d.setPaint(gp);  
  121.     if (this.AeFillBackground == true) {  
  122.       g2d.fillRoundRect(00, w - 1, h - 1, arcs.width, arcs.height);  
  123.     }  
  124.     g2d.drawRoundRect(00, w - 1, h - 1, arcs.width, arcs.height);  
  125.   }  
  126.     
  127.   private void setBg(boolean isOpaque)  
  128.   {  
  129.     Component[] components = getComponents();  
  130.     for (Component component : components)  
  131.     {  
  132.       ((JLabel)component).setOpaque(isOpaque);  
  133.       ((JCheckBox)component).setOpaque(isOpaque);  
  134.       ((JTextField)component).setOpaque(isOpaque);  
  135.       ((JPasswordField)component).setOpaque(isOpaque);  
  136.       ((JFormattedTextField)component).setOpaque(isOpaque);  
  137.       ((JToolBar)component).setOpaque(isOpaque);  
  138.       ((JRadioButton)component).setOpaque(isOpaque);  
  139.     }  
  140.   }  
  141. }  

1 comment:

  1. Westcott scissors titanium - Titsanium Art
    Westcott scissors titanium is used for 피망 바카라 decoration, decoration, titanium tv apk mokume gane titanium Shop from Westcott scissors for more titanium chopsticks items - 1xbet login including jewelry & dresses - including

    ReplyDelete