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, int hgap, int vgap) 

Source Link

Document

Creates a new flow layout manager with the indicated alignment and the indicated horizontal and vertical gaps.

Usage

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);//from w  w w.j  ava  2  s  . co  m
    frame.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));

    JPanel navigation_panel_wrap = new JPanel() {
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(250, 700);
        }
    };
    JPanel content_panel_wrap = new JPanel() {
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(750, 700);
        }
    };

    content_panel_wrap.setBackground(Color.green);
    navigation_panel_wrap.setBackground(Color.red);

    frame.add(navigation_panel_wrap);
    frame.add(content_panel_wrap);
    frame.pack();
    frame.setVisible(true);

}

From source file:FlowLayoutChangingGap.java

public static void main(String[] args) {

    JFrame aWindow = new JFrame("This is a Flow Layout");
    aWindow.setBounds(50, 50, 500, 500);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    FlowLayout flow = new FlowLayout(FlowLayout.LEFT, 20, 30);
    Container content = aWindow.getContentPane(); // Get the content pane
    content.setLayout(flow); // Set the container layout mgr
    for (int i = 1; i <= 6; i++) {
        content.add(new JButton("Press " + i)); // Add a Button to content pane
    }//from  ww w  .jav  a 2s .  c om
    aWindow.setVisible(true); // Display the window
}

From source file:Main.java

public static void main(String args[]) {
    JPanel container = new ScrollablePanel();
    container.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
    for (int i = 0; i < 20; ++i) {
        JPanel p = new JPanel();
        p.setPreferredSize(new Dimension(50, 50));
        p.add(new JLabel("" + i));
        container.add(p);//from   w  ww . j a  va2 s  .c  o  m
    }

    JScrollPane scroll = new JScrollPane(container);
    scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(scroll);
    f.pack();
    f.setSize(250, 300);
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    FlowLayout layout = new FlowLayout(FlowLayout.LEADING, horizontalGap, verticalGap);
    JButton button = new JButton("Discard");
    JLabel[] panels = new JLabel[5];

    JFrame frame = new JFrame("Poker");
    frame.setSize(width, height);//from ww  w  . ja  v a  2 s .c  om
    frame.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);

    JPanel deckPanel = new JPanel(layout);
    for (int i = 0; i < 5; i++) {
        panels[i] = new JLabel("" + i);
        deckPanel.add(panels[i]);
    }
    frame.getContentPane().add(deckPanel);
    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    buttonPanel.add(button);
    frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();

    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JFrame frame = new JFrame("Layout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    int horizontalGap = 20;
    int verticalGap = 10;
    Container contentPane = frame.getContentPane();
    FlowLayout flowLayout = new FlowLayout(FlowLayout.LEADING, horizontalGap, verticalGap);
    contentPane.setLayout(flowLayout);// ww w.  jav a  2 s .c om
    frame.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

    for (int i = 1; i <= 5; i++) {
        contentPane.add(new JButton("Button  " + i));
    }
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new BorderLayout(5, 5));

    int sz = 4;//from  ww  w .  jav a2  s . c  o m
    Container content = new JPanel(new GridLayout(sz, 0, 2, 2));
    for (int f = 0; f < sz * sz; f++) {
        content.add(new JButton());
    }
    gui.add(content, BorderLayout.CENTER);

    Container info = new JPanel(new FlowLayout(FlowLayout.CENTER, 50, 5));
    info.add(new JLabel("Flow"));
    info.add(new JLabel("Layout"));
    gui.add(info, BorderLayout.PAGE_START);

    gui.add(new JLabel("Label"), BorderLayout.LINE_END);

    JOptionPane.showMessageDialog(null, gui);
}

From source file:Main.java

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

    JPanel contentPane = new JPanel();
    contentPane.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
    JTextField tfield1 = new JTextField(10);
    JTextField tfield2 = new JTextField(10);

    FocusListener tfieldListener = new FocusListener() {
        @Override/* w w w  .j  ava 2 s.c  o  m*/
        public void focusGained(FocusEvent fe) {
        }

        @Override
        public void focusLost(FocusEvent fe) {
            String num1 = tfield1.getText().trim();
            String num2 = tfield2.getText().trim();
            if (num1 == null || num1.equals(""))
                num1 = "0";
            if (num2 == null || num2.equals(""))
                num2 = "0";
            System.out.println(Integer.toString(Integer.parseInt(num1) + Integer.parseInt(num2)));
        }
    };

    tfield1.addFocusListener(tfieldListener);
    tfield2.addFocusListener(tfieldListener);

    ((AbstractDocument) tfield1.getDocument()).setDocumentFilter(new MyDocumentFilter());
    ((AbstractDocument) tfield2.getDocument()).setDocumentFilter(new MyDocumentFilter());

    contentPane.add(tfield1);
    contentPane.add(tfield2);

    frame.setContentPane(contentPane);
    frame.pack();
    frame.setLocationByPlatform(true);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    int x = 5;//from  w w w .j  a  v a  2  s .  c o m
    int y = 5;
    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(x, y));
    for (int i = 0; i < x * y; i++) {
        JButton button = new JButton(String.valueOf(i));
        button.setPreferredSize(new Dimension(100, 100));
        panel.add(button);
    }
    JPanel container = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
    container.add(panel);
    JScrollPane scrollPane = new JScrollPane(container);
    f.getContentPane().add(scrollPane);

    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

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

    JPanel gui = new JPanel(new BorderLayout(5, 5));

    JPanel plafComponents = new JPanel(new FlowLayout(FlowLayout.RIGHT, 3, 3));
    plafComponents.setBorder(new TitledBorder("FlowLayout(FlowLayout.RIGHT, 3,3)"));

    UIManager.LookAndFeelInfo[] plafInfos = UIManager.getInstalledLookAndFeels();
    String[] plafNames = new String[plafInfos.length];
    for (int ii = 0; ii < plafInfos.length; ii++) {
        plafNames[ii] = plafInfos[ii].getName();
    }/*from w w  w .  j  a  v  a2 s  .  com*/
    JComboBox plafChooser = new JComboBox(plafNames);
    plafComponents.add(plafChooser);

    JCheckBox pack = new JCheckBox("Pack on PLAF change", true);
    plafComponents.add(pack);

    plafChooser.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            int index = plafChooser.getSelectedIndex();
            try {
                UIManager.setLookAndFeel(plafInfos[index].getClassName());
                SwingUtilities.updateComponentTreeUI(frame);
                if (pack.isSelected()) {
                    frame.pack();
                    frame.setMinimumSize(frame.getSize());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });

    gui.add(plafComponents, BorderLayout.NORTH);

    JPanel dynamicLabels = new JPanel(new BorderLayout(4, 4));
    dynamicLabels.setBorder(new TitledBorder("BorderLayout(4,4)"));
    gui.add(dynamicLabels, BorderLayout.WEST);

    final JPanel labels = new JPanel(new GridLayout(0, 2, 3, 3));
    labels.setBorder(new TitledBorder("GridLayout(0,2,3,3)"));

    JButton addNew = new JButton("Add Another Label");
    dynamicLabels.add(addNew, BorderLayout.NORTH);
    addNew.addActionListener(new ActionListener() {

        private int labelCount = 0;

        public void actionPerformed(ActionEvent ae) {
            labels.add(new JLabel("Label " + ++labelCount));
            frame.validate();
        }
    });

    dynamicLabels.add(new JScrollPane(labels), BorderLayout.CENTER);

    String[] header = { "Name", "Value" };
    String[] a = new String[0];
    String[] names = System.getProperties().stringPropertyNames().toArray(a);
    String[][] data = new String[names.length][2];
    for (int ii = 0; ii < names.length; ii++) {
        data[ii][0] = names[ii];
        data[ii][1] = System.getProperty(names[ii]);
    }
    DefaultTableModel model = new DefaultTableModel(data, header);
    JTable table = new JTable(model);

    JScrollPane tableScroll = new JScrollPane(table);
    Dimension tablePreferred = tableScroll.getPreferredSize();
    tableScroll.setPreferredSize(new Dimension(tablePreferred.width, tablePreferred.height / 3));

    JPanel imagePanel = new JPanel(new GridBagLayout());
    JLabel imageLabel = new JLabel("test");
    imagePanel.add(imageLabel, null);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tableScroll, new JScrollPane(imagePanel));
    gui.add(splitPane, BorderLayout.CENTER);

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

From source file:Main.java

public static void main(String[] args) {
    JTextField[] txtAllAverages;//from w w w  .j av a2s .c  o  m
    int testCount = 2;

    txtAllAverages = new JTextField[testCount];

    JPanel inputControls = new JPanel(new BorderLayout(5, 5));

    JPanel inputControlsLabels = new JPanel(new GridLayout(0, 1, 3, 3));
    JPanel inputControlsFields = new JPanel(new GridLayout(0, 1, 3, 3));
    inputControls.add(inputControlsLabels, BorderLayout.WEST);
    inputControls.add(inputControlsFields, BorderLayout.CENTER);
    for (int i = 0; i < testCount; i++) {
        inputControlsLabels.add(new JLabel("Test score: "));
        JTextField field = new JTextField(10);
        inputControlsFields.add(field);
        txtAllAverages[i] = field;
    }

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 2));

    controls.add(new JButton("Reset"));
    controls.add(new JButton("Submit"));

    JPanel gui = new JPanel(new BorderLayout(10, 10));
    gui.setBorder(new TitledBorder("Averages"));
    gui.add(inputControls, BorderLayout.CENTER);
    gui.add(controls, BorderLayout.SOUTH);

    JFrame f = new JFrame();
    f.setContentPane(gui);

    f.pack();
    f.setLocationByPlatform(true);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
}