List of usage examples for java.awt FlowLayout CENTER
int CENTER
To view the source code for java.awt FlowLayout CENTER.
Click Source Link
From source file:Main.java
public static void main(String[] argv) throws Exception { JButton component1 = new JButton(); JButton component2 = new JButton(); int align = FlowLayout.CENTER; // or LEFT, RIGHT JPanel panel = new JPanel(new FlowLayout(align)); panel.add(component1);//from w w w . ja va 2 s . c o m panel.add(component2); }
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 www . ja v a2s .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) { JFrame frame = new JFrame("Tool Tip Demo"); frame.setSize(200, 200);//from ww w . ja v a2 s .co m frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel label = new JLabel("Hover on me!"); label.setToolTipText("My JLabel Tool Tip"); frame.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER)); frame.getContentPane().add(label); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JPanel gui = new JPanel(new BorderLayout(2, 3)); JPanel buttonConstrsint = new JPanel(new FlowLayout(FlowLayout.CENTER)); JButton getQuotesButton = new JButton("Load"); buttonConstrsint.add(getQuotesButton); gui.add(buttonConstrsint, BorderLayout.NORTH); getQuotesButton.addActionListener(e -> { String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" }; Object[][] data = { { "A", "B", "Snowboarding", new Integer(5), new Boolean(false) }, { "C", "D", "Pool", new Integer(10), new Boolean(false) } }; JTable table = new JTable(data, columnNames); JScrollPane scrollPane = new JScrollPane(table); table.setFillsViewportHeight(true); gui.add(scrollPane, BorderLayout.CENTER); gui.revalidate();/* ww w.ja v a2s.co m*/ gui.repaint(); }); JOptionPane jOptionPane = new JOptionPane(gui); JDialog dialog = jOptionPane.createDialog(new JFrame(), "title"); dialog.setSize(200, 200); dialog.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 w w w . j a v a2s . c om 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.setLayout(new BorderLayout()); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); JPanel northPanel = new JPanel(new GridLayout(2, 1)); JPanel welcomePanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); welcomePanel.add(new JLabel("Welcome")); northPanel.add(welcomePanel);//from w w w . ja v a 2s . c o m JPanel radioPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); JRadioButton button1 = new JRadioButton("Button 1", true); JRadioButton button2 = new JRadioButton("Button 2", false); ButtonGroup group = new ButtonGroup(); group.add(button1); group.add(button2); radioPanel.add(button1); radioPanel.add(button2); northPanel.add(radioPanel); JPanel middlePanel = new JPanel(new GridLayout(3, 3)); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { middlePanel.add(new JButton("Button " + i + j)); } } JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); southPanel.add(new JLabel("Whose turn:")); southPanel.add(new JButton("Reset")); frame.add(northPanel, BorderLayout.NORTH); frame.add(middlePanel, BorderLayout.CENTER); frame.add(southPanel, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setTitle("Example2"); f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER)); p1.setBorder(new TitledBorder(new LineBorder(Color.BLACK), "JPanel 1")); for (int i = 0; i < NB1; i++) p1.add(new JButton("Button " + i)); JPanel p2 = new JPanel(new FlowLayout(FlowLayout.CENTER)); p2.setBorder(new TitledBorder(new LineBorder(Color.BLACK), "JPanel 2")); for (int i = NB1; i < NB2; i++) p2.add(new JButton("Button " + i)); JPanel p3 = new JPanel(new FlowLayout(FlowLayout.CENTER)); p3.setBorder(new TitledBorder(new LineBorder(Color.BLACK), "JPanel 3")); for (int i = NB2; i < NB3; i++) p3.add(new JButton("Button " + i)); JPanel global = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; // added gbc.weightx = 1.0f; // added gbc.gridy = 0;// w w w . j a va 2s . co m global.add(p1, gbc); gbc.gridy++; global.add(p2, gbc); gbc.gridy++; global.add(p3, gbc); f.add(global); f.pack(); f.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;// w w w.j a va2s. 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) { 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);// w w w.j a va 2s. com 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) { JTextField[] txtAllAverages;// w w w . j a v a 2 s. 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); }