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:HyperlinkTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();

    final JEditorPane ep = new JEditorPane();

    try {//from  w ww. ja  v a  2s  .com
        ep.setPage("http://www.java2s.com");
    } catch (IOException e) {
        System.err.println("Bad URL: " + e);
        System.exit(-1);
    }

    HyperlinkListener listener = new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                try {
                    ep.setPage(e.getURL());
                } catch (IOException ioe) {
                    System.err.println("Error loading: " + ioe);
                }
            }
        }
    };
    ep.addHyperlinkListener(listener);
    ep.setEditable(false);
    JScrollPane pane = new JScrollPane(ep);
    contentPane.add(pane, BorderLayout.CENTER);
    frame.setSize(640, 480);
    frame.show();
}

From source file:ElementSample.java

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

    final JTextArea textArea = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(textArea);

    JButton button = new JButton("Show Elements");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Document document = textArea.getDocument();
            ElementIterator iterator = new ElementIterator(document);
            Element element = iterator.first();
            while (element != null) {
                System.out.println(element.getStartOffset());
                element = iterator.next();
            }//from  www. ja v a2 s.  c  om
        }
    };
    button.addActionListener(actionListener);

    frame.add(scrollPane, BorderLayout.CENTER);
    frame.add(button, BorderLayout.SOUTH);

    frame.setSize(250, 250);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame();
    Container pane = f.getContentPane();
    Icon icon = new RedOvalIcon();
    final Action action = new MyAction("Hello", icon);
    // Add tooltip
    action.putValue(Action.SHORT_DESCRIPTION, "World");
    JToolBar jt1 = new JToolBar();
    JButton b1 = new JButton(action);
    jt1.add(b1);/* w ww  .j av  a  2s. c  o  m*/
    pane.add(jt1, BorderLayout.NORTH);
    JToolBar jt2 = new JToolBar();
    JButton b2 = new JButton(action);
    jt2.add(b2);
    pane.add(jt2, BorderLayout.SOUTH);
    JButton jb = new JButton("Toggle Action");
    jb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            action.setEnabled(!action.isEnabled());
        }
    });
    pane.add(jb, BorderLayout.CENTER);
    f.setSize(200, 200);
    f.show();
}

From source file:TabSample.java

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

    JTabbedPane tabbedPane = new JTabbedPane();
    String titles[] = { "General", "Security", "Content", "Connection", "Programs", "Advanced" };
    int mnemonic[] = { KeyEvent.VK_G, KeyEvent.VK_S, KeyEvent.VK_C, KeyEvent.VK_O, KeyEvent.VK_P,
            KeyEvent.VK_A };//from w w w  .  ja  v a  2  s  .  com
    for (int i = 0, n = titles.length; i < n; i++) {
        add(tabbedPane, titles[i], mnemonic[i]);
        tabbedPane.setBackgroundAt(i, colors[i]);
    }
    frame.add(tabbedPane, BorderLayout.CENTER);
    frame.setSize(400, 150);
    frame.setVisible(true);
}

From source file:MainClass.java

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

    final JTextArea textArea = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(textArea);

    JButton button = new JButton("Show Elements");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Document document = textArea.getDocument();
            ElementIterator iterator = new ElementIterator(document);
            Element element = iterator.first();
            while (element != null) {
                System.out.println(element.getStartOffset());
                element = iterator.next();
            }/*from  w  ww.  ja  v  a  2  s .  c om*/
        }
    };
    button.addActionListener(actionListener);

    frame.add(scrollPane, BorderLayout.CENTER);
    frame.add(button, BorderLayout.SOUTH);

    frame.setSize(250, 250);
    frame.setVisible(true);

}

From source file:TreeNodeVector.java

public static void main(final String args[]) {
    UIManager.put("Tree.openIcon", new ImageIcon("yourFile.gif"));

    JFrame frame = new JFrame("JTreeSample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Vector<String> v1 = new TreeNodeVector<String>("Two", new String[] { "Mercury", "Venus", "Mars" });
    Vector<Object> v2 = new TreeNodeVector<Object>("Three");
    v2.add(System.getProperties());
    v2.add(v1);//from w  w w .ja v a 2  s  .  co m
    Object rootNodes[] = { v1, v2 };
    Vector<Object> rootVector = new TreeNodeVector<Object>("Root", rootNodes);
    JTree tree = new JTree(rootVector);
    frame.add(new JScrollPane(tree), BorderLayout.CENTER);

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

}

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame();
    Container contentPane = frame.getContentPane();
    JTextArea b = new JTextArea();
    b.setPreferredSize(new Dimension(600, 600));
    JScrollPane pane = new JScrollPane(b);
    AdjustmentListener hListener = new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            System.out.println("Horizontal: ");
            dumpInfo(e);//from w w w. j a  v  a 2 s  .c o  m
        }
    };
    JScrollBar hBar = pane.getHorizontalScrollBar();
    hBar.addAdjustmentListener(hListener);
    AdjustmentListener vListener = new AdjustmentListener() {
        public void adjustmentValueChanged(AdjustmentEvent e) {
            System.out.println("Vertical: ");
            dumpInfo(e);
        }
    };
    JScrollBar vBar = pane.getVerticalScrollBar();
    vBar.addAdjustmentListener(vListener);
    contentPane.add(pane, BorderLayout.CENTER);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(String args[]) {
    SynthLookAndFeel synth = new SynthLookAndFeel();
    try {//from   w w  w  .ja  v a2 s . c o  m
        Class aClass = MainClass.class;
        InputStream is = aClass.getResourceAsStream("config.xml");
        if (is == null) {
            System.err.println("Unable to find theme configuration");
            System.exit(-1);
        }
        synth.load(is, aClass);
    } catch (ParseException e) {
        System.err.println("Unable to load theme configuration");
        System.exit(-2);
    }
    try {
        UIManager.setLookAndFeel(synth);
    } catch (javax.swing.UnsupportedLookAndFeelException e) {
        System.err.println("Unable to change look and feel");
        System.exit(-3);
    }
    JFrame frame = new JFrame("Synth Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton button = new JButton("Hello, Synth");
    frame.add(button, BorderLayout.CENTER);
    JTextField textField = new JTextField();
    frame.add(textField, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:ElementSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Element Example");
    Container content = frame.getContentPane();

    final JTextArea textArea = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(textArea);

    JButton button = new JButton("Show Elements");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            Document document = textArea.getDocument();
            ElementIterator iterator = new ElementIterator(document);
            Element element = iterator.first();
            while (element != null) {
                System.out.println(element.getStartOffset());
                element = iterator.next();
            }//from w  w w .  j  av a  2 s.c o  m
        }
    };
    button.addActionListener(actionListener);

    content.add(scrollPane, BorderLayout.CENTER);
    content.add(button, BorderLayout.SOUTH);

    frame.setSize(250, 250);
    frame.setVisible(true);
}

From source file:AbstractSample.java

public static void main(String args[]) {
    TableModel model = new AbstractTableModel() {
        Object rowData[][] = { { "one", "ichi" }, { "two", "ni" }, { "three", "san" }, { "four", "shi" },
                { "five", "go" }, { "six", "roku" }, { "seven", "shichi" }, { "eight", "hachi" },
                { "nine", "kyu" }, { "ten", "ju" } };

        Object columnNames[] = { "English", "Japanese" };

        public String getColumnName(int column) {
            return columnNames[column].toString();
        }/*from  w ww  .j a v  a  2 s  . c o m*/

        public int getRowCount() {
            return rowData.length;
        }

        public int getColumnCount() {
            return columnNames.length;
        }

        public Object getValueAt(int row, int col) {
            return rowData[row][col];
        }
    };
    JFrame frame = new JFrame("Abstract Sample");
    JTable table = new JTable(model);
    JScrollPane scrollPane = new JScrollPane(table);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}