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(int align) 

Source Link

Document

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

Usage

From source file:Main.java

public static boolean showModalDialogOnEDT(JComponent contents, String title, String okButtonMessage,
        String cancelButtonMessage, ModalityType modalityType, final boolean systemExitOnDisposed) {

    class Result {
        boolean OK = false;
    }//from  www .  jav  a 2  s.  c o m
    final Result result = new Result();

    final JDialog dialog = new JDialog((Frame) null, title, true) {
        @Override
        public void dispose() {
            super.dispose();
            if (systemExitOnDisposed) {
                System.exit(0);
            }
        }
    };

    // ensure it doesn't block other dialogs
    if (modalityType != null) {
        dialog.setModalityType(modalityType);
    }

    // See http://stackoverflow.com/questions/1343542/how-do-i-close-a-jdialog-and-have-the-window-event-listeners-be-notified
    dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
    if (okButtonMessage != null) {
        buttonPane.add(new JButton(new AbstractAction(okButtonMessage) {

            @Override
            public void actionPerformed(ActionEvent e) {
                result.OK = true;
                dialog.dispose();
            }
        }));
    }

    if (cancelButtonMessage != null) {
        buttonPane.add(new JButton(new AbstractAction(cancelButtonMessage) {

            @Override
            public void actionPerformed(ActionEvent e) {
                dialog.dispose();
            }
        }));
    }

    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel.setLayout(new BorderLayout());
    panel.add(contents, BorderLayout.CENTER);
    panel.add(buttonPane, BorderLayout.SOUTH);

    // startup frame
    dialog.getContentPane().add(panel);
    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.pack();

    // This hopefully centres the dialog even though the parameter is null 
    // see http://stackoverflow.com/questions/213266/how-do-i-center-a-jdialog-on-screen
    dialog.setLocationRelativeTo(null);
    dialog.setVisible(true);

    return result.OK;
}

From source file:Main.java

public Main() {

    super();/*from  w ww .java2  s  . c o m*/
    java.util.List<String> list = new ArrayList<String>();

    list.add("A");
    list.add("B");
    list.add("C");
    list.add("D");

    Object[] arrayObject = list.toArray();
    String[] data = Arrays.copyOf(arrayObject, arrayObject.length, String[].class); // java 1.6+
    JComboBox<String> combo = new JComboBox<>(data);

    setLayout(new FlowLayout(FlowLayout.CENTER));
    add(combo, BorderLayout.CENTER);
}

From source file:Main.java

public Main() {
    super();//from  w  ww.  j av a 2s. c  o  m
    states = new JComboBox<String>(new String[] { "Select a State", "AL", "AK", "AZ", "AR", "CA", "CO", "CT",
            "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN",
            "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI",
            "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY" });

    setLayout(new FlowLayout(FlowLayout.CENTER));
    add(states, BorderLayout.CENTER);

    states.addItemListener(e -> {
        if (states.getSelectedIndex() > 0) {
            System.out.println("YOU CLICK INDEX- " + states.getSelectedIndex());
        }
    });
}

From source file:Main.java

public Main() {
    tabbedPane.add(new JScrollPane(createTabbedPanel()), "Tab " + i);
    add.addActionListener(e -> {/*from  w ww.  j a  v a 2 s . com*/
        i++;
        tabbedPane.add(new JScrollPane(createTabbedPanel()), "Tab " + i);
    });

    JFrame frame = new JFrame();
    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
    buttonPanel.add(add);
    frame.add(buttonPanel, BorderLayout.PAGE_START);
    frame.add(tabbedPane);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

public Main() {
    dialog.setLayout(new GridLayout());
    yes.addActionListener(this);
    no.addActionListener(this);
    JPanel btnPanel = new JPanel();
    btnPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
    btnPanel.add(yes);//  w w  w  .  jav  a 2 s.  c o  m
    btnPanel.add(no);
    dialog.add(message, "Center");
    dialog.add(btnPanel, "South");
    dialog.pack();
    dialog.setVisible(true);
    dialog.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    new Thread(this).start();
}

From source file:Main.java

public Main() {
    JLabel label = new JLabel("Text Field");
    JTextField textField = new JTextField(20);
    JRadioButton rb1 = new JRadioButton("Radio 1");
    JRadioButton rb2 = new JRadioButton("Radio 2");
    JButton button = new JButton("Button");

    JPanel panel1 = new JPanel();
    panel1.add(label);//  w ww.j a va  2  s. co  m
    panel1.add(textField);

    JPanel panel2 = new JPanel();
    panel2.add(rb1);
    panel2.add(rb2);

    JPanel panel3 = new JPanel(new FlowLayout(FlowLayout.TRAILING));
    panel3.add(button);

    JPanel panel4 = new JPanel(new GridLayout(3, 1));
    panel4.add(panel1);
    panel4.add(panel2);
    panel4.add(panel3);

    setLayout(new GridBagLayout());
    add(panel4);
}

From source file:ToolbarFrame2.java

public ToolbarFrame2() {
    setSize(450, 250);//from w  w w  .j a  va2 s .co  m

    ActionListener printListener = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            System.out.println(ae.getActionCommand());
        }
    };

    // JPanel works similarly to Panel, so we'll use it
    JPanel toolbar = new JPanel();
    toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));

    cutButton = new JButton("Cut");
    cutButton.addActionListener(printListener);
    toolbar.add(cutButton);

    copyButton = new JButton("Copy");
    copyButton.addActionListener(printListener);
    toolbar.add(copyButton);

    pasteButton = new JButton("Paste");
    pasteButton.addActionListener(printListener);
    toolbar.add(pasteButton);

    add(toolbar, BorderLayout.NORTH); // The new BorderLayout add

    JPanel lnfPanel = new JPanel();
    macButton = new JButton("Mac");
    macButton.addActionListener(printListener);
    lnfPanel.add(macButton);
    javaButton = new JButton("Metal");
    javaButton.addActionListener(printListener);
    lnfPanel.add(javaButton);
    motifButton = new JButton("Motif");
    motifButton.addActionListener(printListener);
    lnfPanel.add(motifButton);
    winButton = new JButton("Windows");
    winButton.addActionListener(printListener);
    lnfPanel.add(winButton);
    add(lnfPanel, BorderLayout.SOUTH);
}

From source file:ToolbarFrame1.java

public ToolbarFrame1() {
    super("Toolbar Example (AWT)");
    setSize(450, 250);/*from  w  ww. j a  va 2  s . com*/
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    ActionListener printListener = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            System.out.println(ae.getActionCommand());
        }
    };

    Panel toolbar = new Panel();
    toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));

    cutButton = new Button("Cut");
    cutButton.addActionListener(printListener);
    toolbar.add(cutButton);

    copyButton = new Button("Copy");
    copyButton.addActionListener(printListener);
    toolbar.add(copyButton);

    pasteButton = new Button("Paste");
    pasteButton.addActionListener(printListener);
    toolbar.add(pasteButton);

    add(toolbar, BorderLayout.NORTH);
}

From source file:CardFrame.java

public CardFrame(String title) {
    setLayout(new BorderLayout(10, 10));
    nextCard.addActionListener(this);
    prevCard.addActionListener(this);
    firstCard.addActionListener(this);
    lastCard.addActionListener(this);

    Panel buttonsPanel = new Panel(new FlowLayout(FlowLayout.CENTER));
    buttonsPanel.add(firstCard);/*from w w  w  . j  a v a2 s . c  o m*/
    buttonsPanel.add(prevCard);
    buttonsPanel.add(nextCard);
    buttonsPanel.add(lastCard);

    setCardLayout();
    add(BorderLayout.CENTER, cardPanel);
    add(BorderLayout.NORTH, buttonsPanel);
}

From source file:Main.java

private JPanel makeMainInnerPanel() {
    JPanel row1 = makeHorizontalPanel("one", "two", "three", "four", "five");
    JPanel row2 = makeHorizontalPanel("six", "seven", "eight");
    JPanel row3 = makeHorizontalPanel("nine", "ten", "eleven");
    JPanel m = new JPanel(new FlowLayout(FlowLayout.LEFT));
    m.add(row1);/*from w  ww . j a  v  a  2s  .  co  m*/
    m.add(row2);
    m.add(row3);
    return m;
}