Example usage for javax.swing JLabel setBorder

List of usage examples for javax.swing JLabel setBorder

Introduction

In this page you can find the example usage for javax.swing JLabel setBorder.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The component's border.")
public void setBorder(Border border) 

Source Link

Document

Sets the border of this component.

Usage

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Sample Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Border softBevelBorder = new SoftBevelBorder(BevelBorder.RAISED, Color.RED, Color.RED.darker(), Color.PINK,
            Color.PINK.brighter());

    JLabel aLabel = new JLabel("Bevel");
    aLabel.setBorder(softBevelBorder);
    aLabel.setHorizontalAlignment(JLabel.CENTER);

    frame.add(aLabel);/*from w w  w . j  a va2 s .c  o m*/
    frame.setSize(400, 200);
    frame.setVisible(true);
}

From source file:ChangingTitleBorderDirection.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Sample Borders");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Border lineBorder = new LineBorder(Color.RED, 5);

    Font font = new Font("Serif", Font.ITALIC, 12);
    Border titledBorder = new TitledBorder(lineBorder, "Hello", TitledBorder.LEFT, TitledBorder.BELOW_BOTTOM,
            font, Color.RED);//from  w  w  w  .  j  ava2 s .com

    JLabel aLabel = new JLabel("Bevel");
    aLabel.setBorder(titledBorder);
    aLabel.setHorizontalAlignment(JLabel.CENTER);

    frame.add(aLabel);
    frame.setSize(400, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    List<Phone> phones = new ArrayList<>();
    phones.add(new Phone("Galaxy", 12345));
    phones.add(new Phone("iPhone", 12345));

    JPanel panel = new JPanel(new GridLayout(0, 1));
    for (Phone phone : phones) {
        String html = "<html><body style='width:100px'>Phone: " + phone.getName() + "<br/>Model: "
                + phone.getModel() + "</body></html>";
        JLabel label = new JLabel(html);
        label.setBorder(new MatteBorder(0, 0, 1, 0, Color.BLACK));
        panel.add(label);//from  w w w  . j  a v a 2s.co m

    }
    JOptionPane.showMessageDialog(null, panel, "Phone List", JOptionPane.PLAIN_MESSAGE);
}

From source file:Main.java

public static void main(String[] args) {
    JLabel l = new JLabel("Text");
    l.setBorder(new ThreeDimensionalBorder(Color.BLACK, 200, 5));

    JOptionPane.showMessageDialog(null, l);
}

From source file:OvalBorder.java

public static void main(String[] s) {
    JFrame f = new JFrame("Oval Border");
    f.setSize(100, 100);/* w ww. j  a  va  2s. c  o  m*/

    JPanel p = new JPanel(new GridLayout(0, 1, 5, 5));
    JLabel l = new JLabel("Oval Border");

    l.setBorder(new OvalBorder());

    p.add(l);
    p.setBorder(new OvalBorder());

    f.getContentPane().add(p);
    f.show();
}

From source file:Borders.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Borders");

    int center = SwingConstants.CENTER;
    JLabel labelOne = new JLabel("raised BevelBorder", center);
    labelOne.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    JLabel labelTwo = new JLabel("EtchedBorder", center);
    labelTwo.setBorder(BorderFactory.createEtchedBorder());
    JLabel labelThree = new JLabel("MatteBorder", center);
    labelThree.setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, Color.pink));
    JLabel labelFour = new JLabel("TitledBorder", center);
    Border etch = BorderFactory.createEtchedBorder();
    labelFour.setBorder(BorderFactory.createTitledBorder(etch, "Title"));
    JLabel labelFive = new JLabel("TitledBorder", center);
    Border low = BorderFactory.createLoweredBevelBorder();
    labelFive//  ww  w  .  ja v  a  2  s . c o  m
            .setBorder(BorderFactory.createTitledBorder(low, "Title", TitledBorder.RIGHT, TitledBorder.BOTTOM));
    JLabel labelSix = new JLabel("CompoundBorder", center);
    Border one = BorderFactory.createEtchedBorder();
    Border two = BorderFactory.createMatteBorder(4, 4, 4, 4, Color.blue);
    labelSix.setBorder(BorderFactory.createCompoundBorder(one, two));

    frame.setLayout(new GridLayout(3, 2));
    frame.add(labelOne);
    frame.add(labelTwo);
    frame.add(labelThree);
    frame.add(labelFour);
    frame.add(labelFive);
    frame.add(labelSix);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

License:asdf

public static void main(String args[]) {
    JFrame f = new JFrame("Label Demo");
    f.setLayout(new FlowLayout());
    f.setSize(200, 360);/*from   w  ww. j  a  va2 s. co m*/
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JLabel label = new JLabel("asdf");
    Border border = BorderFactory.createLineBorder(Color.BLACK);
    label.setBorder(border);
    label.setPreferredSize(new Dimension(150, 100));
    f.add(label);

    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    SpringLayout layout = new SpringLayout();
    JPanel p = new JPanel(layout);
    p.setBorder(BorderFactory.createLineBorder(Color.GREEN, 10));

    JLabel l1 = new JLabel("label: width=90%", SwingConstants.CENTER);
    l1.setBorder(BorderFactory.createLineBorder(Color.RED, 1));
    JButton l2 = new JButton("button: width=50%");

    Spring panelw = layout.getConstraint(WIDTH, p);

    SpringLayout.Constraints c1 = layout.getConstraints(l1);
    c1.setX(Spring.constant(0));/*from  w w w  .  j ava2 s.  c  om*/
    c1.setY(Spring.constant(20));
    c1.setWidth(Spring.scale(panelw, 0.9f));
    p.add(l1);

    SpringLayout.Constraints c2 = layout.getConstraints(l2);
    c2.setWidth(Spring.scale(panelw, 0.5f));
    layout.putConstraint(SOUTH, l2, -20, SOUTH, p);
    layout.putConstraint(EAST, l2, -20, EAST, p);
    p.add(l2);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.getContentPane().add(p);
    f.setSize(320, 240);
    f.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    String rows[][] = { { "A", "a" }, { "B", "b" }, { "E", "e" } };
    String headers[] = { "Upper", "Lower" };

    JFrame frame = new JFrame("Label Header");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTable table = new JTable(rows, headers);
    JScrollPane scrollPane = new JScrollPane(table);

    Border headerBorder = UIManager.getBorder("TableHeader.cellBorder");

    JLabel headerLabel1 = new JLabel(headers[0], JLabel.CENTER);
    headerLabel1.setBorder(headerBorder);
    JLabel headerLabel2 = new JLabel(headers[1], JLabel.CENTER);
    headerLabel2.setBorder(headerBorder);

    TableCellRenderer renderer = new JComponentTableCellRenderer();

    TableColumnModel columnModel = table.getColumnModel();

    TableColumn column0 = columnModel.getColumn(0);
    TableColumn column1 = columnModel.getColumn(1);

    column0.setHeaderRenderer(renderer);
    column0.setHeaderValue(headerLabel1);

    column1.setHeaderRenderer(renderer);
    column1.setHeaderValue(headerLabel2);

    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);/*from w  w w .j  a  v a2  s .c om*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    JLabel label = new JLabel("java2s.com", JLabel.LEFT);
    Border border = BorderFactory.createLineBorder(Color.BLACK);
    label.setBorder(border);

    JOptionPane.showMessageDialog(null, label);

}