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

public static void main(String args[]) {
    JFrame frame = new JFrame("Changed Renderer");
    JTree tree = new JTree();
    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree.getCellRenderer();

    renderer.setFont(new Font("Dialog", Font.BOLD | Font.ITALIC, 32));
    int rowHeight = tree.getRowHeight();
    if (rowHeight <= 0) {
        tree.setRowHeight(rowHeight - 1);
    }/*ww w  . j a  v a  2 s  .  c o  m*/

    // Swap background colors
    Color backgroundSelection = renderer.getBackgroundSelectionColor();
    renderer.setBackgroundSelectionColor(renderer.getBackgroundNonSelectionColor());
    renderer.setBackgroundNonSelectionColor(backgroundSelection);

    // Swap text colors
    Color textSelection = renderer.getTextSelectionColor();
    renderer.setTextSelectionColor(renderer.getTextNonSelectionColor());
    renderer.setTextNonSelectionColor(textSelection);

    JScrollPane scrollPane = new JScrollPane(tree);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame();
    aWindow.setBounds(200, 200, 200, 200);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Box left = Box.createVerticalBox();
    left.add(Box.createVerticalStrut(30));
    ButtonGroup radioGroup = new ButtonGroup();
    JRadioButton rbutton;//  w w w. java  2s  .  c o m
    radioGroup.add(rbutton = new JRadioButton("Red"));
    left.add(rbutton);
    left.add(Box.createVerticalStrut(30));
    radioGroup.add(rbutton = new JRadioButton("Green"));
    left.add(rbutton);
    left.add(Box.createVerticalStrut(30));
    radioGroup.add(rbutton = new JRadioButton("Blue"));
    left.add(rbutton);
    left.add(Box.createVerticalStrut(30));
    radioGroup.add(rbutton = new JRadioButton("Yellow"));
    left.add(rbutton);

    left.add(Box.createGlue());

    JPanel leftPanel = new JPanel(new BorderLayout());
    leftPanel.add(left, BorderLayout.CENTER);

    Box right = Box.createVerticalBox();
    right.add(Box.createVerticalStrut(30));
    right.add(new JCheckBox("Dashed"));
    right.add(Box.createVerticalStrut(30));
    right.add(new JCheckBox("Thick"));
    right.add(Box.createVerticalStrut(30));
    right.add(new JCheckBox("Rounded"));

    right.add(Box.createGlue());

    JPanel rightPanel = new JPanel(new BorderLayout());
    rightPanel.add(right, BorderLayout.CENTER);

    Box top = Box.createHorizontalBox();
    top.add(leftPanel);
    top.add(Box.createHorizontalStrut(5));
    top.add(rightPanel);

    Container content = aWindow.getContentPane();
    content.setLayout(new BorderLayout());
    content.add(top, BorderLayout.CENTER);

    BoxLayout box = new BoxLayout(content, BoxLayout.Y_AXIS);

    content.setLayout(box);
    content.add(top);

    aWindow.setVisible(true);
}

From source file:Main.java

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

    JPanel panel = new JPanel() {
        public boolean isOptimizedDrawingEnabled() {
            return false;
        }/* w w w . ja v a2s.c o m*/
    };
    LayoutManager overlay = new OverlayLayout(panel);
    panel.setLayout(overlay);

    JButton button = new JButton("Small");
    button.setMaximumSize(new Dimension(25, 25));
    button.setBackground(Color.white);
    button.setAlignmentX(0.0f);
    button.setAlignmentY(0.0f);
    panel.add(button);

    button = new JButton("Medium");
    button.setMaximumSize(new Dimension(50, 50));
    button.setBackground(Color.gray);
    button.setAlignmentX(0.0f);
    button.setAlignmentY(0.0f);
    panel.add(button);

    button = new JButton("Large");
    button.setMaximumSize(new Dimension(100, 100));
    button.setBackground(Color.black);
    button.setAlignmentX(0.0f);
    button.setAlignmentY(0.0f);
    panel.add(button);

    frame.add(panel, BorderLayout.CENTER);

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

From source file:KeymapExample.java

public static void main(String[] args) {
    JTextArea area = new JTextArea(6, 32);
    Keymap parent = area.getKeymap();
    Keymap newmap = JTextComponent.addKeymap("KeymapExampleMap", parent);

    KeyStroke u = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK);
    Action actionU = new UpWord();
    newmap.addActionForKeyStroke(u, actionU);

    Action actionList[] = area.getActions();
    Hashtable lookup = new Hashtable();
    for (int j = 0; j < actionList.length; j += 1)
        lookup.put(actionList[j].getValue(Action.NAME), actionList[j]);

    KeyStroke L = KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK);
    Action actionL = (Action) lookup.get(DefaultEditorKit.selectLineAction);
    newmap.addActionForKeyStroke(L, actionL);

    KeyStroke W = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK);
    Action actionW = (Action) lookup.get(DefaultEditorKit.selectWordAction);
    newmap.addActionForKeyStroke(W, actionW);

    area.setKeymap(newmap);// ww w.  j  av a  2s .  c  o m

    JFrame f = new JFrame("KeymapExample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER);
    area.setText("www.\n java2s \n .com.");
    f.pack();
    f.setVisible(true);
}

From source file:ResizeSplit.java

public static void main(String args[]) {
    String title = "Resize Split";

    final JFrame vFrame = new JFrame(title);
    vFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton topButton = new JButton("Top");
    JButton bottomButton = new JButton("Bottom");
    final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setTopComponent(topButton);
    splitPane.setBottomComponent(bottomButton);
    ActionListener oneActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            splitPane.setResizeWeight(1.0);
            vFrame.setSize(300, 250);//from ww  w . j  a  va2  s . c  o  m
            vFrame.validate();
        }
    };
    bottomButton.addActionListener(oneActionListener);

    ActionListener anotherActionListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            splitPane.setResizeWeight(0.5);
            vFrame.setSize(300, 250);
            vFrame.validate();
        }
    };
    topButton.addActionListener(anotherActionListener);
    vFrame.getContentPane().add(splitPane, BorderLayout.CENTER);
    vFrame.setSize(300, 150);
    vFrame.setVisible(true);

}

From source file:TabSample.java

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

    StyledDocument document = new DefaultStyledDocument();

    //TabStop.ALIGN_CENTER, TabStop.ALIGN_DECIMAL,TabStop.ALIGN_LEFT, TabStop.ALIGN_RIGHT
    //"\tBAR\n", "\tCENTER\n", "\t3.14159265\n", "\tLEFT\n", "\tRIGHT\n" };

    SimpleAttributeSet attributes = new SimpleAttributeSet();

    TabStop tabstop = new TabStop(150, TabStop.ALIGN_BAR, TabStop.LEAD_DOTS);
    int position = document.getLength();
    document.insertString(position, "TabStop.ALIGN_BAR", null);

    TabSet tabset = new TabSet(new TabStop[] { tabstop });
    StyleConstants.setTabSet(attributes, tabset);
    document.setParagraphAttributes(position, 1, attributes, false);

    JTextPane textPane = new JTextPane(document);
    textPane.setEditable(false);/* ww w .  j  a v  a2  s  .c  o  m*/
    JScrollPane scrollPane = new JScrollPane(textPane);
    frame.add(scrollPane, BorderLayout.CENTER);

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

From source file:SimpleAttributeBoldItalicColor.java

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

    StyledDocument document = new DefaultStyledDocument();

    SimpleAttributeSet attributes = new SimpleAttributeSet();
    attributes = new SimpleAttributeSet();
    attributes.addAttribute(StyleConstants.CharacterConstants.Bold, Boolean.FALSE);
    attributes.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.FALSE);
    attributes.addAttribute(StyleConstants.CharacterConstants.Foreground, Color.LIGHT_GRAY);

    try {//www .j a  va 2s . c o  m
        document.insertString(document.getLength(), " Bold, Italic and light gray color", attributes);
    } catch (BadLocationException badLocationException) {
        System.err.println("Bad insert");
    }

    JTextPane textPane = new JTextPane(document);
    textPane.setEditable(false);
    JScrollPane scrollPane = new JScrollPane(textPane);

    frame.add(scrollPane, BorderLayout.CENTER);

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

From source file:MainClass.java

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

    JDesktopPane desktop = new JDesktopPane();
    JInternalFrame internalFrames[] = { new JInternalFrame("Can Do All", true, true, true, true),
            new JInternalFrame("Not Resizable", false, true, true, true),
            new JInternalFrame("Not Closable", true, false, true, true),
            new JInternalFrame("Not Maximizable", true, true, false, true),
            new JInternalFrame("Not Iconifiable", true, true, true, false) };

    InternalFrameListener internalFrameListener = new InternalFrameIconifyListener();

    int pos = 0;// ww w . j  av a 2  s  .co  m
    for (JInternalFrame internalFrame : internalFrames) {
        desktop.add(internalFrame);

        internalFrame.setBounds(pos * 25, pos * 25, 200, 100);
        pos++;

        internalFrame.addInternalFrameListener(internalFrameListener);

        JLabel label = new JLabel(internalFrame.getTitle(), JLabel.CENTER);
        internalFrame.add(label, BorderLayout.CENTER);

        internalFrame.setVisible(true);
    }

    frame.add(desktop, BorderLayout.CENTER);
    frame.setSize(500, 300);
    frame.setVisible(true);
}

From source file:MultiHighlight.java

public static void main(String args[]) {
    JFrame frame = new JFrame("MultiHighlight");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTextArea area = new JTextArea(5, 20);
    area.setText("ww\nw.java2s.c\nom");
    frame.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER);

    JButton b = new JButton("Highlight All Vowels");
    b.addActionListener(new MultiHighlight(area, "aeiouAEIOU"));
    frame.getContentPane().add(b, BorderLayout.SOUTH);
    frame.pack();//from w w  w  . ja v a 2  s .c o m
    frame.setVisible(true);
}

From source file:GridLayoutPane.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);/*w  ww.jav a2  s.  com*/
        }
    });

    frame.getContentPane().add(new GridLayoutPane(), BorderLayout.CENTER);
    // Finally, set the size of the main window, and pop it up.
    frame.setSize(600, 400);
    frame.setVisible(true);
}