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

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

    Container panel1 = makeIt("Left", Component.LEFT_ALIGNMENT);
    Container panel2 = makeIt("Center", Component.CENTER_ALIGNMENT);
    Container panel3 = makeIt("Right", Component.RIGHT_ALIGNMENT);

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new FlowLayout());
    contentPane.add(panel1);//w w w  .  j av  a  2 s .  c om
    contentPane.add(panel2);
    contentPane.add(panel3);

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

From source file:Main.java

public static void main(String[] args) {
    JDialog dialog;/*w  ww  .j av  a2  s  .c  o m*/
    JList jlist;
    ActionListener otherListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("current");
        }
    };
    JButton okButton = new JButton("OK");
    okButton.addActionListener(e -> close(true));
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(e -> close(false));
    jlist = new JList(new String[] { "A", "B", "C", "D", "E", "F", "G" });
    jlist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jlist.setVisibleRowCount(5);
    JScrollPane scroll = new JScrollPane(jlist);
    JPanel buttonsPanel = new JPanel(new FlowLayout());
    buttonsPanel.add(okButton);
    buttonsPanel.add(cancelButton);
    JPanel content = new JPanel(new BorderLayout());
    content.add(scroll, BorderLayout.CENTER);
    content.add(buttonsPanel, BorderLayout.SOUTH);
    dialog = new JDialog((Frame) null, true);
    dialog.setContentPane(content);
    dialog.pack();
    dialog.getRootPane().registerKeyboardAction(otherListener, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    dialog.getRootPane().registerKeyboardAction(otherListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    dialog.getRootPane().getInputMap().put(KeyStroke.getKeyStroke("SPACE"), "doSomething");
    dialog.getRootPane().getActionMap().put("doSomething", new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    dialog.setVisible(true);
}

From source file:AlignX.java

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

    Container panel1 = makeIt("R", Component.RIGHT_ALIGNMENT);
    Container panel2 = makeIt("C", Component.CENTER_ALIGNMENT);
    Container panel3 = makeIt("L", Component.LEFT_ALIGNMENT);

    contentPane.setLayout(new FlowLayout());
    contentPane.add(panel1);/*  w ww  .j  a  v  a2  s  .  c om*/
    contentPane.add(panel2);
    contentPane.add(panel3);

    frame.pack();
    frame.show();
}

From source file:DragMouseAdapter.java

public static void main(String[] args) {
    JFrame f = new JFrame("Icon Drag & Drop");
    ImageIcon icon1 = new ImageIcon("a.png");
    ImageIcon icon2 = new ImageIcon("b.png");
    ImageIcon icon3 = new ImageIcon("c.png");

    JButton button = new JButton(icon2);

    JLabel label1 = new JLabel(icon1, JLabel.CENTER);
    JLabel label2 = new JLabel(icon3, JLabel.CENTER);

    MouseListener listener = new DragMouseAdapter();
    label1.addMouseListener(listener);/*w ww . j av a  2s  .c o  m*/
    label2.addMouseListener(listener);

    label1.setTransferHandler(new TransferHandler("icon"));
    button.setTransferHandler(new TransferHandler("icon"));
    label2.setTransferHandler(new TransferHandler("icon"));

    f.setLayout(new FlowLayout());
    f.add(label1);
    f.add(button);
    f.add(label2);
    f.pack();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] arguments) {
    JPanel panel = new JPanel(new BorderLayout());
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel);//from ww  w .  j  ava2s  .c om
    frame.setBounds(20, 20, 200, 200);
    frame.setVisible(true);

    JProgressBar progressBar = new JProgressBar();
    progressBar.setIndeterminate(true);
    progressBar.setVisible(false);
    JButton loadButton = new JButton("Load memberlist");
    loadButton.setEnabled(true);
    loadButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    progressBar.setVisible(true);
                    // do my stuff here...
                    try {
                        Thread.sleep(2000);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    progressBar.setVisible(false);
                }
            }).start();
        }
    });
    JPanel container = new JPanel(new FlowLayout());
    container.add(loadButton);
    container.add(progressBar);
    panel.add(container);
}

From source file:org.eclipse.swt.snippets.Snippet337.java

public static void main(String args[]) {
    display = new Display();
    EventQueue.invokeLater(() -> {
        JFrame mainFrame = new JFrame("Main Window");
        mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        mainFrame.addWindowListener(new Snippet337.CloseListener());
        JPanel mainPanel = new JPanel();
        mainPanel.setLayout(new FlowLayout());
        JButton launchBrowserButton = new JButton("Launch Browser");
        launchBrowserButton.addActionListener(e -> {
            JFrame childFrame = new JFrame();
            final Canvas canvas = new Canvas();
            childFrame.setSize(850, 650);
            childFrame.getContentPane().add(canvas);
            childFrame.setVisible(true);
            display.asyncExec(() -> {
                Shell shell = SWT_AWT.new_Shell(display, canvas);
                shell.setSize(800, 600);
                Browser browser = new Browser(shell, SWT.NONE);
                browser.setLayoutData(new GridData(GridData.FILL_BOTH));
                browser.setSize(800, 600);
                browser.setUrl("http://www.eclipse.org");
                shell.open();/*from w  ww  .ja  va 2s . c  om*/
            });
        });

        mainPanel.add(new JTextField("a JTextField"));
        mainPanel.add(launchBrowserButton);
        mainFrame.getContentPane().add(mainPanel, BorderLayout.CENTER);
        mainFrame.pack();
        mainFrame.setVisible(true);
    });
    display.addListener(SWT.Close, event -> EventQueue.invokeLater(() -> {
        Frame[] frames = Frame.getFrames();
        for (int i = 0; i < frames.length; i++) {
            frames[i].dispose();
        }
    }));
    while (!display.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
}

From source file:ButtonModel.java

public static void main(String[] args) {
    final JButton ok = new JButton("ok");

    JCheckBox cb = new JCheckBox("Enabled", true);

    ok.setBounds(40, 30, 80, 25);// w w w  .jav a2  s .  co m
    ok.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            DefaultButtonModel model = (DefaultButtonModel) ok.getModel();
            if (model.isEnabled())
                System.out.println("Enabled: true");
            else
                System.out.println("Enabled: false");

            if (model.isArmed())
                System.out.println("Armed: true");
            else
                System.out.println("Armed: false");

            if (model.isPressed())
                System.out.println("Pressed: true");
            else
                System.out.println("Pressed: false");
        }

    });

    cb.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (ok.isEnabled())
                ok.setEnabled(false);
            else
                ok.setEnabled(true);
        }
    });

    JFrame f = new JFrame();
    f.setLayout(new FlowLayout());
    f.add(ok);
    f.add(cb);
    f.setSize(350, 250);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    final JButton ok = new JButton("ok");
    JCheckBox cb = new JCheckBox("Enabled", true);
    cb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ok.isEnabled())
                ok.setEnabled(false);/*from   w w  w .  j a v  a 2s  . c  o m*/
            else
                ok.setEnabled(true);
        }
    });

    ButtonModel model = new DefaultButtonModel() {
        public void setEnabled(boolean b) {
            if (b)
                System.out.println("Pressed: true");
            else
                System.out.println("Pressed: false");

            super.setEnabled(b);
        }

        public void setArmed(boolean b) {
            if (b)
                System.out.println("Armed: true");
            else
                System.out.println("Armed: false");

            super.setArmed(b);
        }

        public void setPressed(boolean b) {
            if (b)
                System.out.println("Pressed: true");
            else
                System.out.println("Pressed: false");

            super.setPressed(b);
        }

    };

    ok.setModel(model);

    JFrame f = new JFrame();
    f.setLayout(new FlowLayout());
    f.add(ok);
    f.add(cb);

    f.setSize(350, 250);
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}

From source file:ResourceModExample.java

public static void main(String[] args) {
    Border border = BorderFactory.createRaisedBevelBorder();
    Border tripleBorder = new CompoundBorder(new CompoundBorder(border, border), border);

    UIManager.put("Button.border", tripleBorder);

    UIManager.put("InternalFrame.closeIcon", new ImageIcon("close.gif"));
    UIManager.put("InternalFrame.iconizeIcon", new ImageIcon("iconify.gif"));
    UIManager.put("InternalFrame.maximizeIcon", new ImageIcon("maximize.gif"));
    UIManager.put("InternalFrame.altMaximizeIcon", new ImageIcon("altMax.gif"));

    UIManager.put("InternalFrame.titleFont", new Font("Serif", Font.ITALIC, 12));

    UIManager.put("ScrollBar.width", new Integer(30));

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container c = f.getContentPane();

    JDesktopPane desk = new JDesktopPane();
    c.add(desk, BorderLayout.CENTER);

    JButton cut = new JButton("Cut");
    JButton copy = new JButton("Copy");
    JButton paste = new JButton("Paste");

    JPanel p = new JPanel(new FlowLayout());
    p.add(cut);/*www. j  a v  a2s  . com*/
    p.add(copy);
    p.add(paste);
    c.add(p, BorderLayout.SOUTH);

    JInternalFrame inf = new JInternalFrame("MyFrame", true, true, true, true);
    JLabel l = new JLabel(new ImageIcon("luggage.jpeg"));
    JScrollPane scroll = new JScrollPane(l);
    inf.setContentPane(scroll);
    inf.setBounds(10, 10, 350, 280);
    desk.add(inf);
    inf.setVisible(true);

    f.setSize(380, 360);
    f.setVisible(true);
}

From source file:DisplayMessage.java

public static void main(String[] args) {
    /*/*from   w w w. ja  v  a  2 s .  c  o m*/
     * Step 1: Create the components
     */
    JLabel msgLabel = new JLabel(); // Component to display the question
    JButton yesButton = new JButton(); // Button for an affirmative response
    JButton noButton = new JButton(); // Button for a negative response

    /*
     * Step 2: Set properties of the components
     */
    msgLabel.setText(args[0]); // The msg to display
    msgLabel.setBorder(new EmptyBorder(10, 10, 10, 10)); // A 10-pixel margin 
    yesButton.setText((args.length >= 2) ? args[1] : "Yes"); // Text for Yes button
    noButton.setText((args.length >= 3) ? args[2] : "No"); // Text for no button

    /*
     * Step 3: Create containers to hold the components
     */
    JFrame win = new JFrame("Message"); // The main application window
    JPanel buttonbox = new JPanel(); // A container for the two buttons

    /*
     * Step 4: Specify LayoutManagers to arrange components in the containers
     */
    win.getContentPane().setLayout(new BorderLayout()); // layout on borders
    buttonbox.setLayout(new FlowLayout()); // layout left-to-right

    /*
     * Step 5: Add components to containers, with optional layout constraints
     */
    buttonbox.add(yesButton); // add yes button to the panel
    buttonbox.add(noButton); // add no button to the panel

    // add JLabel to window, telling the BorderLayout to put it in the middle
    win.getContentPane().add(msgLabel, "Center");

    // add panel to window, telling the BorderLayout to put it at the bottom
    win.getContentPane().add(buttonbox, "South");

    /*
     * Step 6: Arrange to handle events in the user interface.
     */
    yesButton.addActionListener(new ActionListener() { // Note: inner class
        // This method is called when the Yes button is clicked.
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });

    noButton.addActionListener(new ActionListener() { // Note: inner class
        // This method is called when the No button is clicked.
        public void actionPerformed(ActionEvent e) {
            System.exit(1);
        }
    });

    /*
     * Step 7: Display the GUI to the user
     */
    win.pack(); // Set the size of the window based its children's sizes.
    win.show(); // Make the window visible.
}