import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.event.MouseMotionListener; import javax.swing.JCheckBox; import javax.swing.JFormattedTextField; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JRadioButton; import javax.swing.JTextField; import javax.swing.JToolBar; /** * * @author Andi.irah */ public class AeGradientPanel extends JPanel { public Color AeStartColor = Color.MAGENTA; public Color AeEndColor = Color.BLUE; public boolean AeTranspControls = true; public int AeGradientFocus = 500; public int AeBorderRadius = 10; public boolean AeFillBackground = true; public boolean isAeFillBackground() { return this.AeFillBackground; } public void setAeFillBackground(boolean AeFillBackground) { this.AeFillBackground = AeFillBackground; } public int getAeBorderRadius() { return this.AeBorderRadius; } public void setAeBorderRadius(int AeBorderRadius) { this.AeBorderRadius = AeBorderRadius; } public Color getAeStartColor() { return this.AeStartColor; } public void setAeStartColor(Color AeStartColor) { this.AeStartColor = AeStartColor; } public Color getAeEndColor() { return this.AeEndColor; } public void setAeEndColor(Color AeEndColor) { this.AeEndColor = AeEndColor; } public boolean isAeTranspControls() { return this.AeTranspControls; } public void setAeTranspControls(boolean AeTranspControls) { this.AeTranspControls = AeTranspControls; } public int getAeGradientFocus() { return this.AeGradientFocus; } public void setAeGradientFocus(int AeGradientFocus) { this.AeGradientFocus = AeGradientFocus; } public AeGradientPanel() { setPreferredSize(new Dimension(380, 280)); if (this.AeTranspControls) { setBg(true); } else { setBg(false); } } public synchronized void addMouseMotionListener(MouseMotionListener l) { super.addMouseMotionListener(l); } protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); Dimension arcs = new Dimension(this.AeBorderRadius, this.AeBorderRadius); GradientPaint gp = new GradientPaint(0.0F, 0.0F, this.AeStartColor, this.AeGradientFocus, h, this.AeEndColor); g2d.setPaint(gp); if (this.AeFillBackground == true) { g2d.fillRoundRect(0, 0, w - 1, h - 1, arcs.width, arcs.height); } g2d.drawRoundRect(0, 0, w - 1, h - 1, arcs.width, arcs.height); } private void setBg(boolean isOpaque) { Component[] components = getComponents(); for (Component component : components) { ((JLabel)component).setOpaque(isOpaque); ((JCheckBox)component).setOpaque(isOpaque); ((JTextField)component).setOpaque(isOpaque); ((JPasswordField)component).setOpaque(isOpaque); ((JFormattedTextField)component).setOpaque(isOpaque); ((JToolBar)component).setOpaque(isOpaque); ((JRadioButton)component).setOpaque(isOpaque); } } }
Post Top Ad
Your Ad Spot
Friday, October 18, 2019
[Java] [Swing] [Netbeans] [ Custom Palette ] jPanel Gradient Background
Post Top Ad
Your Ad Spot
Author Details
Semakin kamu diam, semakin banyak kamu mendengar.