Example usage for java.awt FlowLayout FlowLayout

List of usage examples for java.awt FlowLayout FlowLayout

Introduction

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

Prototype

public FlowLayout() 

Source Link

Document

Constructs a new FlowLayout with a centered alignment and a default 5-unit horizontal and vertical gap.

Usage

From source file:Main.java

public static void main(String[] args) {
    final JFrame parent1 = new JFrame("Parent Frame 1");
    parent1.setLayout(new FlowLayout());
    parent1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JButton button = new JButton("Application modal dialog");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JDialog dialog = new JDialog(parent1, "Application-Modal Dialog",
                    Dialog.ModalityType.APPLICATION_MODAL);
            dialog.setBounds(200, 150, 200, 150);
            dialog.setVisible(true);/*from   w ww  .ja  v  a 2  s  .  c o m*/
        }
    });
    parent1.add(button);
    parent1.setBounds(100, 100, 200, 150);
    parent1.setVisible(true);

    JFrame parent2 = new JFrame("Parent Frame 2");
    parent2.setBounds(500, 100, 200, 150);
    parent2.setVisible(true);
}

From source file:FlowLayoutSettingGaps.java

public static void main(String[] args) {
    JFrame aWindow = new JFrame("This is a Flow Layout");
    aWindow.setBounds(30, 30, 300, 300); // Size
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    FlowLayout flow = new FlowLayout(); // Create a layout manager
    flow.setHgap(35); // Set the horizontal gap
    Container content = aWindow.getContentPane(); // Get the content pane
    content.setLayout(flow); // Set the container layout mgr
    // Now add six button components
    for (int i = 1; i <= 6; i++) {
        content.add(new JButton("Press " + i)); // Add a Button to content pane
    }/*from  w  w  w  . jav  a  2  s .  co  m*/
    aWindow.setVisible(true); // Display the window
}

From source file:ButtonFocus.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Focus Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton focusButton = new JButton("Focused");
    JButton notFocusButton = new JButton("Not Focused");
    frame.setLayout(new FlowLayout());
    frame.add(focusButton);//  ww  w  .ja  v  a2  s.c  om
    frame.add(notFocusButton);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:SimpleDnD.java

public static void main(String[] args) {
    JTextField field = new JTextField(10);
    JButton button = new JButton("Button");
    JFrame f = new JFrame();
    f.setTitle("Simple Drag & Drop");

    f.setLayout(new FlowLayout());
    f.add(button);//ww  w. j  a va2 s  .  c o  m
    f.add(field);

    field.setDragEnabled(true);
    button.setTransferHandler(new TransferHandler("text"));

    f.setSize(330, 150);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:ButtonFocus.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Action Sample");

    JButton focusButton = new JButton("Focused");
    JButton notFocusButton = new JButton("Not Focused");

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new FlowLayout());
    contentPane.add(focusButton);//w ww .  ja v a2 s.c  o  m
    contentPane.add(notFocusButton);
    frame.setSize(300, 100);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JCheckBox a = new JCheckBox("A");
    a.setSelected(true);// w w w .  j  a  v  a  2s  .  co  m
    JCheckBox b = new JCheckBox("B");
    JCheckBox c = new JCheckBox("C");
    JCheckBox d = new JCheckBox("D");

    JFrame frame = new JFrame();
    frame.setLayout(new FlowLayout());
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.add(new JLabel("Car Features"));
    frame.add(a);
    frame.add(b);
    frame.add(c);
    frame.add(d);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JProgressBar progressBar = new JProgressBar();
    JButton button = new JButton("Start");
    JFrame f = new JFrame();
    f.setLayout(new FlowLayout());
    f.add(progressBar);/*w w  w. j  a  v a  2s  .com*/
    f.add(button);

    ActionListener updateProBar = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            int val = progressBar.getValue();
            if (val >= 100) {
                //  timer.stop();
                button.setText("End");
                return;
            }
            progressBar.setValue(++val);
        }
    };
    Timer timer = new Timer(50, updateProBar);
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (timer.isRunning()) {
                timer.stop();
                button.setText("Start");
            } else if (button.getText() != "End") {
                timer.start();
                button.setText("Stop");
            }
        }
    });
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String avg[]) throws Exception {
    BufferedImage img = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));
    ImageIcon icon = new ImageIcon(img);
    JFrame frame = new JFrame();
    frame.setLayout(new FlowLayout());
    frame.setSize(200, 300);/*from ww  w  . j  a  va 2 s . c om*/
    JLabel lbl = new JLabel();
    lbl.setIcon(icon);
    frame.add(lbl);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame jFrame = new JFrame();
    jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    jFrame.setSize(400, 300);//from  ww  w . j a v a 2s . c om
    JPanel panel = new JPanel(new FlowLayout());
    jFrame.setContentPane(panel);

    JEditorPane editor = new JEditorPane();
    new Main().remove_border(editor);
    panel.add(editor);

    jFrame.setVisible(true);
}

From source file:Main.java

public static void main(String[] argv) {
    JFrame frame = new JFrame();
    JButton component1 = new JButton("1");
    JButton component2 = new JButton("2");
    JButton component3 = new JButton("3");

    frame.setLayout(new FlowLayout());
    frame.add(component1);//from w  w w .j  a va  2 s .  c  om
    frame.add(component2);
    frame.add(component3);

    frame.pack();
    frame.setVisible(true);

    System.out.println(findPrevFocus().getName());
}