Example usage for java.awt BorderLayout CENTER

List of usage examples for java.awt BorderLayout CENTER

Introduction

In this page you can find the example usage for java.awt BorderLayout CENTER.

Prototype

String CENTER

To view the source code for java.awt BorderLayout CENTER.

Click Source Link

Document

The center layout constraint (middle of container).

Usage

From source file:MainClass.java

public static void main(String args[]) {
    JFrame f = new JFrame("JSlider Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JSlider slider = new JSlider();
    slider.setMinorTickSpacing(5);/*from ww  w.  j a v a  2  s . c om*/
    slider.setMajorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setSnapToTicks(true);
    slider.setPaintTrack(false);
    slider.setPaintLabels(true);
    f.add(slider, BorderLayout.CENTER);
    f.setSize(300, 100);
    f.setVisible(true);
}

From source file:Main.java

public static void main(final String args[]) {
    String labels[] = { "A", "B", "C", "D", "E" };
    JFrame frame = new JFrame("Selection Modes");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JList list1 = new JList(labels);
    JScrollPane sp1 = new JScrollPane(list1);
    sp1.setColumnHeaderView(new JLabel("List"));
    frame.add(sp1, BorderLayout.CENTER);
    frame.setSize(300, 200);//from  w w  w.  j  a  v a2s  . c om
    frame.setVisible(true);

}

From source file:Main.java

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

    JList jlist = new JList(new String[] { "A", "B", "C" });

    jlist.setSelectedIndex(0);// www  . j  a  va2  s .co m
    JScrollPane scrollPane1 = new JScrollPane(jlist);
    frame.add(scrollPane1, BorderLayout.CENTER);

    frame.setSize(640, 300);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("MultiHighlight");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTextArea comp = new JTextArea(5, 20);
    comp.setText("this is a test");
    frame.getContentPane().add(new JScrollPane(comp), BorderLayout.CENTER);

    String charsToHighlight = "a";
    Highlighter h = comp.getHighlighter();
    h.removeAllHighlights();//  www.  ja v  a2s  .c om
    String text = comp.getText().toUpperCase();

    for (int j = 0; j < text.length(); j += 1) {
        char ch = text.charAt(j);
        if (charsToHighlight.indexOf(ch) >= 0)
            h.addHighlight(j, j + 1, DefaultHighlighter.DefaultPainter);
    }
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

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

    Action action = new ShowAction();
    JCheckBox button = new JCheckBox(action);

    frame.add(button, BorderLayout.CENTER);
    frame.setSize(350, 150);/*w ww  .  j  a v a2s .co  m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JComponent button = new JButton("Cut");
    String tooltiptext = "<html>" + "This is the " + "<img src=\"file:cut.gif\">" + " tool tip text."
            + "</html>";
    button.setToolTipText(tooltiptext);//from w  w w. ja v a 2s . c o  m
    JPanel panel = new JPanel();
    panel.add(button);
    frame.add(panel, BorderLayout.CENTER);
    frame.setSize(400, 400);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel ui = new JPanel(new BorderLayout(1, 1));
    JTabbedPane jtp = new JTabbedPane(JTabbedPane.LEFT);
    jtp.addTab("Apple", new JLabel("Apple"));
    jtp.addTab("Banana", new JLabel("Banana"));
    jtp.addTab("Cherries", new JLabel("Cherries"));
    jtp.addTab("Grapes", new JLabel("Grapes"));
    ui.add(jtp, BorderLayout.CENTER);
    jtp.setPreferredSize(new Dimension(200, 200));
    jtp.addChangeListener(e -> {/*from w w  w  . j a  v a2s .  co m*/
        if (e.getSource() instanceof JTabbedPane) {
            JTabbedPane pane = (JTabbedPane) e.getSource();
            System.out.println("Selected paneNo : " + pane.getSelectedIndex());
        }
    });
}

From source file:Main.java

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

    JTextField nameTextField = new JTextField();
    JLabel nameLabel = new JLabel("Name:");
    nameLabel.setDisplayedMnemonic('N');
    nameLabel.setLabelFor(nameTextField);

    frame.add(nameLabel, BorderLayout.WEST);
    frame.add(nameTextField, BorderLayout.CENTER);

    frame.pack();//  ww  w  . ja  v a 2  s.co m
    frame.setVisible(true);
}

From source file:PaneInsertionMethods.java

public static void main(String[] args) {

    final JTextPane pane = new JTextPane();

    pane.replaceSelection("text");
    pane.insertIcon(new ImageIcon("imageName.gif"));
    pane.insertComponent(new JButton("Click Me"));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(pane, BorderLayout.CENTER);
    frame.setSize(360, 180);/*  ww w. j ava2  s  .  co m*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    int rows = 10;
    int cols = 5;
    JTable table = new JTable(rows, cols);
    JTableHeader header = table.getTableHeader();

    JPanel container = new JPanel(new BorderLayout());

    // Add header in NORTH slot
    container.add(header, BorderLayout.NORTH);

    // Add table itself to CENTER slot
    container.add(table, BorderLayout.CENTER);
}