Example usage for java.awt BorderLayout BorderLayout

List of usage examples for java.awt BorderLayout BorderLayout

Introduction

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

Prototype

public BorderLayout() 

Source Link

Document

Constructs a new border layout with no gaps between components.

Usage

From source file:LabelSampleLoadText.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Label Focus Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name: ");
    label.setDisplayedMnemonic(KeyEvent.VK_N);
    JTextField textField = new JTextField();
    label.setLabelFor(textField);/*w  w  w  .  jav  a2s.  c o  m*/
    panel.add(label, BorderLayout.WEST);
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel, BorderLayout.NORTH);
    frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH);
    frame.setSize(250, 150);
    frame.setVisible(true);

    FileReader reader = null;
    try {
        String filename = "test.txt";
        reader = new FileReader(filename);
        textField.read(reader, filename);
    } catch (IOException exception) {
        System.err.println("Load oops");
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException exception) {
                System.err.println("Error closing reader");
                exception.printStackTrace();
            }
        }
    }

}

From source file:LabelSampleSaveText.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Label Focus Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name: ");
    label.setDisplayedMnemonic(KeyEvent.VK_N);
    JTextField textField = new JTextField();
    label.setLabelFor(textField);//from  w  w w . j  av  a  2s.c  o  m
    panel.add(label, BorderLayout.WEST);
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel, BorderLayout.NORTH);
    frame.add(new JButton("Somewhere Else"), BorderLayout.SOUTH);
    frame.setSize(250, 150);
    frame.setVisible(true);

    textField.setText("your text");
    String filename = "test.txt";

    FileWriter writer = null;
    try {
        writer = new FileWriter(filename);
        textField.write(writer);
    } catch (IOException exception) {
        System.err.println("Save oops");
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException exception) {
                System.err.println("Error closing writer");
                exception.printStackTrace();
            }
        }
    }
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 400);/*  ww  w. j  av a 2s . c  o  m*/

    JDialog dialog = new JDialog(frame, "Dialog", true);

    JPanel mainGui = new JPanel(new BorderLayout());
    mainGui.setBorder(new EmptyBorder(20, 20, 20, 20));
    mainGui.add(new JLabel("Contents go here"), BorderLayout.CENTER);

    JPanel buttonPanel = new JPanel(new FlowLayout());
    mainGui.add(buttonPanel, BorderLayout.SOUTH);

    JButton close = new JButton("Close");
    close.addActionListener(e -> dialog.setVisible(false));

    buttonPanel.add(close);

    frame.setVisible(true);

    dialog.setContentPane(mainGui);
    dialog.pack();
    dialog.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTabbedPane tab = new JTabbedPane();
    tab.addTab("New tab1", new JLabel("1"));
    tab.addTab("New Tab2", new JLabel("2"));
    JPanel p = new JPanel(new BorderLayout());
    p.add(new JLayer<JComponent>(tab, new TopRightCornerLabelLayerUI()));

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(p);//from www.j av a2  s  .c o  m
    f.setSize(320, 240);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    JPanel panel = new JPanel();
    JScrollPane listScrollPane = new JScrollPane();
    String[] stringArray = { "Testing", "This", "Stuff" };
    JList<String> rowList = new JList<>(stringArray);

    rowList.setVisibleRowCount(2);//ww  w.  j  a v  a  2s .  c  o  m
    listScrollPane.setViewportView(rowList);
    panel.setLayout(new BorderLayout());
    panel.add(listScrollPane);
    frame.add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);

}

From source file:OffsetSample.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Offset Example");
    Container content = frame.getContentPane();
    JPanel panel = new JPanel(new BorderLayout());
    JLabel label = new JLabel("Name: ");
    label.setDisplayedMnemonic(KeyEvent.VK_N);
    final JTextField textField = new JTextField();
    label.setLabelFor(textField);//w  ww . j  av a2s  .co m
    panel.add(label, BorderLayout.WEST);
    panel.add(textField, BorderLayout.CENTER);
    content.add(panel, BorderLayout.NORTH);
    JButton button = new JButton("Get Offset");
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            System.out.println("Offset: " + textField.getScrollOffset());
            System.out.println("Visibility: " + textField.getHorizontalVisibility());
            BoundedRangeModel model = textField.getHorizontalVisibility();
            int extent = model.getExtent();
            textField.setScrollOffset(extent);
        }
    };
    button.addActionListener(actionListener);
    content.add(button, BorderLayout.SOUTH);
    frame.setSize(250, 150);
    frame.setVisible(true);
}

From source file:SpinnerDateSample.java

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

    SpinnerModel model1 = new SpinnerDateModel();
    JSpinner spinner1 = new JSpinner(model1);

    JLabel label1 = new JLabel("Dates/Date");
    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(label1, BorderLayout.WEST);
    panel1.add(spinner1, BorderLayout.CENTER);
    frame.add(panel1, BorderLayout.CENTER);

    frame.setSize(200, 90);/*from  ww  w. j  a  v a2  s.c  o  m*/
    frame.setVisible(true);
}

From source file:Main.java

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

    JProgressBar bar = new JProgressBar(JProgressBar.VERTICAL);
    bar.setEnabled(true);//w w w . ja  v a 2 s  .c o  m

    bar.setBackground(Color.YELLOW);
    bar.setForeground(Color.GREEN);

    bar.setStringPainted(true);
    bar.setString("2000 g");
    bar.setValue(65);
    frame.setLayout(new BorderLayout());
    frame.add(bar, BorderLayout.CENTER);
    frame.setSize(500, 400);
    frame.setVisible(true);
}

From source file:MainClass.java

public static void main(final String args[]) {
    JFrame frame = new JFrame("JSpinner Dates");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SpinnerModel model1 = new SpinnerDateModel();
    JSpinner spinner1 = new JSpinner(model1);
    JLabel label1 = new JLabel("All");
    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(label1, BorderLayout.WEST);
    panel1.add(spinner1, BorderLayout.CENTER);
    frame.add(panel1, BorderLayout.NORTH);

    frame.setSize(200, 90);//from  w w w . j a  v a  2  s . com
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    JProgressBar pb = new JProgressBar();
    JTextArea ta = new JTextArea(10, 20);

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new BorderLayout());
    frame.add(new JScrollPane(ta));
    frame.add(pb, BorderLayout.SOUTH);
    frame.pack();//from   ww  w.ja v  a 2s  .c om
    frame.setVisible(true);

    Timer timer = new Timer(250, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            index++;
            if (index >= 100) {
                ((Timer) (e.getSource())).stop();
            }
            ta.append("Line " + index + "\n");
            pb.setValue(index);
        }
    });
    timer.setRepeats(true);
    timer.setCoalesce(true);
    timer.start();
}