List of usage examples for java.awt GridLayout GridLayout
public GridLayout(int rows, int cols, int hgap, int vgap)
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); JFileChooser fc = new JFileChooser(); fc.setMultiSelectionEnabled(true);// w ww . j a v a 2 s . c o m fc.setCurrentDirectory(new File("C:\\tmp")); JButton btn1 = new JButton("Show Dialog"); btn1.addActionListener(e -> fc.showDialog(frame, "Choose")); JButton btn2 = new JButton("Show Open Dialog"); btn2.addActionListener(e -> { int retVal = fc.showOpenDialog(frame); if (retVal == JFileChooser.APPROVE_OPTION) { File[] selectedfiles = fc.getSelectedFiles(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < selectedfiles.length; i++) { sb.append(selectedfiles[i].getName()); sb.append("\n"); } JOptionPane.showMessageDialog(frame, sb.toString()); } }); JButton btn3 = new JButton("Show Save Dialog"); btn3.addActionListener(e -> fc.showSaveDialog(frame)); Container pane = frame.getContentPane(); pane.setLayout(new GridLayout(3, 1, 10, 10)); pane.add(btn1); pane.add(btn2); pane.add(btn3); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { Vector<Double> doubleVector = new Vector<Double>(); Vector<Integer> integerVector = new Vector<Integer>(); Vector<Boolean> booleanVector = new Vector<Boolean>(); Vector<Icon> iconVector = new Vector<Icon>(); Icon icon1 = ((UIManager.getIcon("OptionPane.errorIcon"))); Icon icon2 = (UIManager.getIcon("OptionPane.informationIcon")); Icon icon3 = (UIManager.getIcon("OptionPane.warningIcon")); Icon icon4 = (UIManager.getIcon("OptionPane.questionIcon")); doubleVector.addElement(1.001);/*from w w w.j a v a 2 s . com*/ doubleVector.addElement(10.00); doubleVector.addElement(0.95); doubleVector.addElement(4.2); JComboBox comboBoxDouble = new JComboBox(doubleVector); integerVector.addElement(1); integerVector.addElement(2); integerVector.addElement(3); integerVector.addElement(4); JComboBox comboBoxInteger = new JComboBox(integerVector); booleanVector.add(Boolean.TRUE); booleanVector.add(Boolean.FALSE); JComboBox comboBoxBoolean = new JComboBox(booleanVector); iconVector.addElement(icon1); iconVector.addElement(icon2); iconVector.addElement(icon3); iconVector.addElement(icon4); JComboBox comboBoxIcon = new JComboBox(iconVector); JFrame frame = new JFrame(); frame.setLayout(new GridLayout(2, 2, 5, 5)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(comboBoxDouble); frame.add(comboBoxInteger); frame.add(comboBoxBoolean); frame.add(comboBoxIcon); frame.pack(); frame.setVisible(true); }
From source file:OvalBorder.java
public static void main(String[] s) { JFrame f = new JFrame("Oval Border"); f.setSize(100, 100);/*from w ww . j av a 2s . c om*/ JPanel p = new JPanel(new GridLayout(0, 1, 5, 5)); JLabel l = new JLabel("Oval Border"); l.setBorder(new OvalBorder()); p.add(l); p.setBorder(new OvalBorder()); f.getContentPane().add(p); f.show(); }
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 www. j a v a 2 s . c om 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:BorderSample.java
public static void main(String args[]) { JFrame frame = new JFrame("Sample Borders"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Border bevelBorder = new BevelBorder(BevelBorder.RAISED, Color.red, Color.red.darker(), Color.pink, Color.pink.brighter()); Border emptyBorder = new EmptyBorder(5, 10, 5, 10); Border etchedBorder = new EtchedBorder(EtchedBorder.RAISED, Color.red, Color.pink); Border lineBorder = new LineBorder(Color.red, 5); Icon diamondIcon = new DiamondIcon(Color.red); Border matteBorder = new MatteBorder(5, 10, 5, 10, diamondIcon); Border softBevelBorder = new SoftBevelBorder(BevelBorder.RAISED, Color.red, Color.red.darker(), Color.pink, Color.pink.brighter()); Font font = new Font("Serif", Font.ITALIC, 12); Border titledBorder = new TitledBorder(lineBorder, "Hello", TitledBorder.LEFT, TitledBorder.BELOW_BOTTOM, font, Color.red);/* w w w . j a v a 2s . c o m*/ Border compoundBorder = new CompoundBorder(lineBorder, matteBorder); JLabel bevelLabel = new JLabel("Bevel"); bevelLabel.setBorder(bevelBorder); bevelLabel.setHorizontalAlignment(JLabel.CENTER); JLabel emptyLabel = new JLabel("Empty"); emptyLabel.setBorder(emptyBorder); emptyLabel.setHorizontalAlignment(JLabel.CENTER); JLabel etchedLabel = new JLabel("Etched"); etchedLabel.setBorder(etchedBorder); etchedLabel.setHorizontalAlignment(JLabel.CENTER); JLabel lineLabel = new JLabel("Line"); lineLabel.setBorder(lineBorder); lineLabel.setHorizontalAlignment(JLabel.CENTER); JLabel matteLabel = new JLabel("Matte"); matteLabel.setBorder(matteBorder); matteLabel.setHorizontalAlignment(JLabel.CENTER); JLabel softBevelLabel = new JLabel("Soft Bevel"); softBevelLabel.setBorder(softBevelBorder); softBevelLabel.setHorizontalAlignment(JLabel.CENTER); JLabel titledLabel = new JLabel("Titled"); titledLabel.setBorder(titledBorder); titledLabel.setHorizontalAlignment(JLabel.CENTER); JLabel compoundLabel = new JLabel("Compound"); compoundLabel.setBorder(compoundBorder); compoundLabel.setHorizontalAlignment(JLabel.CENTER); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(2, 4, 5, 5)); contentPane.add(bevelLabel); contentPane.add(emptyLabel); contentPane.add(etchedLabel); contentPane.add(lineLabel); contentPane.add(matteLabel); contentPane.add(softBevelLabel); contentPane.add(titledLabel); contentPane.add(compoundLabel); frame.setSize(400, 200); frame.setVisible(true); }
From source file:CalIcon.java
public static void main(String[] args) { JFrame jf = new JFrame("Calendar"); Container cp = jf.getContentPane(); cp.setLayout(new GridLayout(0, 1, 5, 5)); CalIcon c = new CalIcon(true); cp.add(c);/*from w ww . j av a2 s .co m*/ JButton j = new JButton("As Icon", new CalIcon(false)); cp.add(j); jf.pack(); jf.setVisible(true); }
From source file:Main.java
public static void getPanelGridLayout(JPanel panel, int rows, int cols) { panel.setLayout(new GridLayout(rows, cols, 1, 1)); }
From source file:Main.java
public static JPanel createVerticalPanel(Component[] cms, int vgap) { JPanel pane = new JPanel(new GridLayout(cms.length, 1, 0, vgap)); for (Component c : cms) { pane.add(c);//w w w. j av a2s. co m } return pane; }
From source file:Main.java
public static Component getButtonLayout(int num) { JPanel p = new JPanel(new BorderLayout(3, 3)); p.add(new JLabel("Label " + num), BorderLayout.NORTH); JPanel b = new JPanel(new GridLayout(1, 0, 25, 5)); for (int ii = 1; ii < 4; ii++) { b.add(new JButton("Button " + ii)); }/* www .ja va 2 s . co m*/ p.add(b, BorderLayout.CENTER); return p; }
From source file:Main.java
public Main() { super(new GridLayout(2, 2, 20, 30)); add(new JButton("w w w.j a v a 2 s . c o m")); add(new JButton("w w w.j a v a 2 s . com")); add(new JButton("w w w.java2s.com")); add(new JButton("www.j ava 2 s . c o m")); }