📄 gradientpanel.java
字号:
/* * GradientPanel.java * * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */package org.underworldlabs.swing;import java.awt.Color;import java.awt.GradientPaint;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.LayoutManager;import java.awt.Paint;import javax.swing.JPanel;import javax.swing.UIManager;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the * release of version 3.0.0beta1 has meant a * resetting of CVS revision numbers. * ---------------------------------------------------------- *//** * Simple panel with a left-right gradient background. * * @author Takis Diakoumis * @version $Revision: 1.4 $ * @date $Date: 2006/05/14 06:56:07 $ */public class GradientPanel extends JPanel { /** The component's gradient colour */ private Color gradientColor; /** The component's fill colour */ private Color fillColor; /** Creates a new instance of GradientPanel */ public GradientPanel() { super(); } public GradientPanel(boolean isDoubleBuffered) { super(isDoubleBuffered); } public GradientPanel(LayoutManager layout) { super(layout); } public GradientPanel(LayoutManager layout, boolean isDoubleBuffered) { super(layout, isDoubleBuffered); } public void setColours(Color colour1, Color colour2) { gradientColor = colour1; fillColor = colour2; } public boolean isOpaque() { return true; } /** * Performs the painting for this component. * * @param the <code>Graphics</code> object to * perform the painting */ protected void paintComponent(Graphics g) { super.paintComponent(g); // if we have no colours - use the InternalFrame colours if (gradientColor == null) { gradientColor = UIManager.getColor("InternalFrame.activeTitleBackground"); } if (fillColor == null) { fillColor = UIManager.getColor("InternalFrame.inactiveTitleBackground"); } int width = getWidth(); int height = getHeight(); Graphics2D g2 = (Graphics2D)g; Paint originalPaint = g2.getPaint(); if (gradientColor != null && fillColor != null) { GradientPaint fade = new GradientPaint(0, 0, gradientColor, (int)(width * 0.9), 0, fillColor); g2.setPaint(fade); g2.fillRect(0,0, width, height); } g2.setPaint(originalPaint); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -