Java Tutorial/Swing/EtchedBorder — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Текущая версия на 15:31, 31 мая 2010

14. Creating and Setting an EtchedBorder from BorderFactory

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.border.EtchedBorder;
public class Main {
  public static void main(String[] argv) {
    
    EtchedBorder etchedBorder = (EtchedBorder)BorderFactory.createEtchedBorder();
    JLabel component = new JLabel("label");
    component.setBorder(etchedBorder);
  }
}





14. Creating EtchedBorder with its Constructor

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
public class EtchedBorderSample {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Sample Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Border etchedBorder = new EtchedBorder(EtchedBorder.RAISED, Color.RED, Color.PINK);
    
    JLabel aLabel = new JLabel("Bevel");
    aLabel.setBorder(etchedBorder);
    aLabel.setHorizontalAlignment(JLabel.CENTER);
    frame.add(aLabel);
    frame.setSize(400, 200);
    frame.setVisible(true);
  }
}





14. EtchedBorder

  1. An etched border produces either an etched-in or etched-out effect.
  2. You can specify the type of etching using the field LOWERED or RAISED.
  3. By default, the etched border is of type etched-in.



public EtchedBorder()
Border etchedBorder = new EtchedBorder();

public EtchedBorder(int etchType)
Border etchedBorder = new EtchedBorder(EtchedBorder.RAISED);

public EtchedBorder(Color highlight, Color shadow)
Border etchedBorder = new EtchedBorder(Color.RED, Color.PINK);

public EtchedBorder(int etchType, Color highlight, Color shadow)
Border etchedBorder = new EtchedBorder(EtchedBorder.RAISED, Color.RED, Color.PINK);

public static Border createEtchedBorder()
Border etchedBorder = BorderFactory.createEtchedBorder();

public static Border createEtchedBorder(Color highlight, Color shadow)
Border etchedBorder = BorderFactory.createEtchedBorder(Color.RED, Color.PINK);

public static Border createEtchedBorder(EtchedBorder.RAISED)
Border etchedBorder = BorderFactory.createEtchedBorder(Color.RED, Color.PINK);

public static Border createEtchedBorder(int type, Color highlight, Color shadow)
Border etchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.RAISED, Color.RED, Color.PINK);





14. Raised and Lowered EtchedBorder

import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
public class AnEtchedBorder {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Etched Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
    Border raisedBorder = new EtchedBorder(EtchedBorder.RAISED);
    Border loweredBorder = new EtchedBorder(EtchedBorder.LOWERED);
    JButton raisedButton = new JButton("Raised");
    raisedButton.setBorder(raisedBorder);
    
    JButton loweredButton = new JButton("Lowered");
    loweredButton.setBorder(loweredBorder);
    
    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new GridLayout(1, 2, 5, 5));
    contentPane.add(raisedButton);
    contentPane.add(loweredButton);
    frame.setSize(300, 100);
    frame.setVisible(true);
  }
}