import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.BevelBorder;
public class JFrameSample extends JFrame{
private JPanel panelTree = new JPanel();
private JPanel panelImage = new JPanel();
private JPanel panelWhatEver = new JPanel();
public JFrameSample(){
initGui();
}
private void initGui(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout (null);
this.setSize (800, 600);
JLabel label = new GradientLabel("Test");
label.setForeground(Color.white);
this.panelTree.setBounds (25, 25, 350, 250);
this.panelImage.setBounds (25, 300, 350, 250);
this.panelWhatEver.setBounds(425, 25, 350, 525);
this.panelTree.setBorder(BorderFactory.createBevelBorder (BevelBorder.RAISED, Color.LIGHT_GRAY, Color.GRAY));
this.panelImage.setBorder(BorderFactory.createBevelBorder (BevelBorder.RAISED, Color.LIGHT_GRAY, Color.GRAY));
this.panelWhatEver.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED, Color.LIGHT_GRAY, Color.GRAY));
panelWhatEver.setLayout(new BorderLayout());
panelWhatEver.add(label, BorderLayout.NORTH);
this.add(panelTree);
this.add(panelImage);
this.add(panelWhatEver);
}
public static void main(String[] args) {
new JFrameSample().setVisible(true);
}
private class GradientLabel extends JLabel{
public GradientLabel() {
super();
}
public GradientLabel(Icon image, int horizontalAlignment) {
super(image, horizontalAlignment);
// TODO Auto-generated constructor stub
}
public GradientLabel(Icon image) {
super(image);
// TODO Auto-generated constructor stub
}
public GradientLabel(String text, Icon icon, int horizontalAlignment) {
super(text, icon, horizontalAlignment);
// TODO Auto-generated constructor stub
}
public GradientLabel(String text, int horizontalAlignment) {
super(text, horizontalAlignment);
// TODO Auto-generated constructor stub
}
public GradientLabel(String text) {
super(text);
// TODO Auto-generated constructor stub
}
public void paintComponent(Graphics g) {
// TODO Auto-generated method stub
GradientPaint paint =new GradientPaint(10F, 0F,Color.blue,getWidth()-10, 0F, getBackground());
Graphics2D g2d = (Graphics2D)g;
g2d.setPaint(paint);
g2d.fillRect(0, 0, getWidth(), getHeight());
super.paintComponent(g);
}
}
}