Example usage for javax.swing.border TitledBorder TitledBorder

List of usage examples for javax.swing.border TitledBorder TitledBorder

Introduction

In this page you can find the example usage for javax.swing.border TitledBorder TitledBorder.

Prototype

public TitledBorder(Border border) 

Source Link

Document

Creates a TitledBorder instance with the specified border and an empty title.

Usage

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new BorderLayout());
    gui.setBorder(new TitledBorder("Border Layout"));

    JPanel labels = new JPanel();
    labels.setBorder(new TitledBorder("Flow Layout"));
    labels.add(new JLabel("Label 1"));
    labels.add(new JLabel("Label 2"));

    gui.add(labels, BorderLayout.NORTH);
    gui.add(new JButton("Button"), BorderLayout.SOUTH);

    JOptionPane.showMessageDialog(null, gui);
}

From source file:Main.java

License:asdf

public static void main(String[] argv) {
    LineBorder border1 = new LineBorder(Color.red);
    TitledBorder border2 = new TitledBorder("asdf");

    Border newBorder = BorderFactory.createCompoundBorder(border1, border2);
    JButton component = new JButton("button");
    component.setBorder(newBorder);/* ww w. j  av  a  2s .  co m*/
}

From source file:Main.java

public static void main(String[] args) {
    JTextField account = new JTextField(10);
    JPanel accountPanel = new JPanel(new GridLayout());
    accountPanel.add(account);/*from   w ww.ja v a 2s  . co m*/
    accountPanel.setBorder(new TitledBorder("Account"));

    String[] firstDigitList = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };

    JLabel firstDigitListLabel = new JLabel("Leading Digit Change");
    JPanel firstDigitListPanel = new JPanel(new BorderLayout(4, 2));
    firstDigitListPanel.add(firstDigitListLabel, BorderLayout.WEST);
    JComboBox firstDigitCombo = new JComboBox(firstDigitList);
    firstDigitListPanel.add(firstDigitCombo);
    firstDigitCombo.setSelectedIndex(0);
    firstDigitListPanel.setBorder(new TitledBorder("LDC"));

    JPanel panel = new JPanel();
    panel.add(accountPanel);
    panel.add(firstDigitListPanel);

    int result = JOptionPane.showConfirmDialog(null, panel, "Please Enter Values",
            JOptionPane.OK_CANCEL_OPTION);
}

From source file:Main.java

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

    JPanel gui = new JPanel(new BorderLayout(5, 5));

    JPanel plafComponents = new JPanel(new FlowLayout(FlowLayout.RIGHT, 3, 3));
    plafComponents.setBorder(new TitledBorder("FlowLayout(FlowLayout.RIGHT, 3,3)"));

    UIManager.LookAndFeelInfo[] plafInfos = UIManager.getInstalledLookAndFeels();
    String[] plafNames = new String[plafInfos.length];
    for (int ii = 0; ii < plafInfos.length; ii++) {
        plafNames[ii] = plafInfos[ii].getName();
    }// w  w w.  ja  v a2s.  c  om
    JComboBox plafChooser = new JComboBox(plafNames);
    plafComponents.add(plafChooser);

    JCheckBox pack = new JCheckBox("Pack on PLAF change", true);
    plafComponents.add(pack);

    plafChooser.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            int index = plafChooser.getSelectedIndex();
            try {
                UIManager.setLookAndFeel(plafInfos[index].getClassName());
                SwingUtilities.updateComponentTreeUI(frame);
                if (pack.isSelected()) {
                    frame.pack();
                    frame.setMinimumSize(frame.getSize());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    gui.add(plafComponents, BorderLayout.NORTH);

    JPanel dynamicLabels = new JPanel(new BorderLayout(4, 4));
    dynamicLabels.setBorder(new TitledBorder("BorderLayout(4,4)"));
    gui.add(dynamicLabels, BorderLayout.WEST);

    final JPanel labels = new JPanel(new GridLayout(0, 2, 3, 3));
    labels.setBorder(new TitledBorder("GridLayout(0,2,3,3)"));

    JButton addNew = new JButton("Add Another Label");
    dynamicLabels.add(addNew, BorderLayout.NORTH);
    addNew.addActionListener(new ActionListener() {

        private int labelCount = 0;

        public void actionPerformed(ActionEvent ae) {
            labels.add(new JLabel("Label " + ++labelCount));
            frame.validate();
        }
    });

    dynamicLabels.add(new JScrollPane(labels), BorderLayout.CENTER);

    String[] header = { "Name", "Value" };
    String[] a = new String[0];
    String[] names = System.getProperties().stringPropertyNames().toArray(a);
    String[][] data = new String[names.length][2];
    for (int ii = 0; ii < names.length; ii++) {
        data[ii][0] = names[ii];
        data[ii][1] = System.getProperty(names[ii]);
    }
    DefaultTableModel model = new DefaultTableModel(data, header);
    JTable table = new JTable(model);

    JScrollPane tableScroll = new JScrollPane(table);
    Dimension tablePreferred = tableScroll.getPreferredSize();
    tableScroll.setPreferredSize(new Dimension(tablePreferred.width, tablePreferred.height / 3));

    JPanel imagePanel = new JPanel(new GridBagLayout());
    JLabel imageLabel = new JLabel("test");
    imagePanel.add(imageLabel, null);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tableScroll, new JScrollPane(imagePanel));
    gui.add(splitPane, BorderLayout.CENTER);

    frame.setContentPane(gui);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTextField[] txtAllAverages;//from w w  w  .  j a  v a  2  s .  c  o m
    int testCount = 2;

    txtAllAverages = new JTextField[testCount];

    JPanel inputControls = new JPanel(new BorderLayout(5, 5));

    JPanel inputControlsLabels = new JPanel(new GridLayout(0, 1, 3, 3));
    JPanel inputControlsFields = new JPanel(new GridLayout(0, 1, 3, 3));
    inputControls.add(inputControlsLabels, BorderLayout.WEST);
    inputControls.add(inputControlsFields, BorderLayout.CENTER);
    for (int i = 0; i < testCount; i++) {
        inputControlsLabels.add(new JLabel("Test score: "));
        JTextField field = new JTextField(10);
        inputControlsFields.add(field);
        txtAllAverages[i] = field;
    }

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 2));

    controls.add(new JButton("Reset"));
    controls.add(new JButton("Submit"));

    JPanel gui = new JPanel(new BorderLayout(10, 10));
    gui.setBorder(new TitledBorder("Averages"));
    gui.add(inputControls, BorderLayout.CENTER);
    gui.add(controls, BorderLayout.SOUTH);

    JFrame f = new JFrame();
    f.setContentPane(gui);

    f.pack();
    f.setLocationByPlatform(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:MainClass.java

public static JPanel demo1() {
    JPanel pan = new JPanel(new BorderLayout());
    pan.setBorder(new TitledBorder("Demo 1: format toggles with focus"));

    MaskFormatter withFocus = null, withoutFocus = null;
    try {/*  w  w w  .  jav a 2s. c  om*/
        withFocus = new MaskFormatter("LLLL");
        withoutFocus = new MaskFormatter("UUUU");
    } catch (ParseException pe) {
    }

    DefaultFormatterFactory factory = new DefaultFormatterFactory(withoutFocus, null, withFocus);

    JFormattedTextField field = new JFormattedTextField(factory);
    field.setValue("Four");
    pan.add(field, BorderLayout.CENTER);

    return pan;
}

From source file:Main.java

public static JPanel placeInTitledEtchedJPanel(Component c, String title, Color titleColor) {
    JPanel parent = new JPanel(new BorderLayout());
    parent.add(c, BorderLayout.CENTER);
    TitledBorder tb = new TitledBorder(title);
    tb.setBorder(BorderFactory.createEtchedBorder());
    tb.setTitleColor(titleColor);//from  w w  w. j  av a 2s  . c  o  m
    parent.setBorder(tb);
    return parent;
}

From source file:MainClass.java

public static JPanel demo1() {
    JPanel pan = new JPanel(new BorderLayout());
    pan.setBorder(new TitledBorder("change format midstream"));

    MaskFormatter lowercase = null;
    try {//from w w w  . ja v a 2 s.  co  m
        lowercase = new MaskFormatter("LLLL");
    } catch (ParseException pe) {
    }
    final JFormattedTextField field = new JFormattedTextField(lowercase);
    field.setValue("lower case");
    pan.add(field, BorderLayout.CENTER);

    final JButton change = new JButton("change format");
    JPanel changePanel = new JPanel();
    changePanel.add(change);
    pan.add(changePanel, BorderLayout.SOUTH);

    change.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            try {
                field.commitEdit();
                MaskFormatter uppercase = new MaskFormatter("UUUU");
                DefaultFormatterFactory factory = new DefaultFormatterFactory(uppercase);
                field.setFormatterFactory(factory);
                change.setEnabled(false);
            } catch (ParseException pe) {
            }
        }
    });

    return pan;
}

From source file:FactoryDemo.java

public static JPanel demo1() {
    // Demo 1: field with different formats with focus and without

    JPanel pan = new JPanel(new BorderLayout());
    pan.setBorder(new TitledBorder("Demo 1: format toggles with focus"));

    MaskFormatter withFocus = null, withoutFocus = null;
    try {/* w ww  .j a  va 2s.  c o m*/
        withFocus = new MaskFormatter("LLLL");
        withoutFocus = new MaskFormatter("UUUU");
    } catch (ParseException pe) {
    }

    DefaultFormatterFactory factory = new DefaultFormatterFactory(withoutFocus, null, withFocus);

    JFormattedTextField field = new JFormattedTextField(factory);
    field.setValue("Four");
    pan.add(field, BorderLayout.CENTER);

    return pan;
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    comp.setToolTipText("Some tooltip text for component");
    comp.setBorder(new TitledBorder("Button"));

    System.out.println("X:" + comp.getX() + " Y:" + comp.getY() + " width:" + comp.getWidth() + " height:"
            + comp.getHeight());/*from   w  ww  .j a  v  a2 s. co  m*/

    getContentPane().add(comp);
    pack();

    System.out.println("X:" + comp.getX() + " Y:" + comp.getY() + " width:" + comp.getWidth() + " height:"
            + comp.getHeight());

    setVisible(true);
}