List of usage examples for java.awt BorderLayout SOUTH
String SOUTH
To view the source code for java.awt BorderLayout SOUTH.
Click Source Link
From source file:ItemTest.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); ItemListener listener = new ItemListener() { public void itemStateChanged(ItemEvent e) { System.out.println("Source: " + name(e.getSource())); System.out.println("Item: " + name(e.getItem())); int state = e.getStateChange(); System.out.println("State: " + ((state == ItemEvent.SELECTED) ? "Selected" : "Deselected")); }//from w w w . j a v a 2s . c om private String name(Object o) { if (o instanceof JComponent) { JComponent comp = (JComponent) o; return comp.getName(); } else { return o.toString(); } } }; JPanel panel = new JPanel(new GridLayout(0, 1)); ButtonGroup group = new ButtonGroup(); JRadioButton option = new JRadioButton("French Fries", true); option.setName(option.getText()); option.addItemListener(listener); group.add(option); panel.add(option); option = new JRadioButton("Onion Rings", false); option.setName(option.getText()); option.addItemListener(listener); group.add(option); panel.add(option); option = new JRadioButton("Ice Cream", false); option.setName(option.getText()); option.addItemListener(listener); group.add(option); panel.add(option); contentPane.add(panel, BorderLayout.NORTH); String flavors[] = { "Item 1", "Item 2", "Item 3" }; JComboBox jc = new JComboBox(flavors); jc.setName("Combo"); jc.addItemListener(listener); jc.setMaximumRowCount(4); contentPane.add(jc, BorderLayout.SOUTH); frame.pack(); frame.show(); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Options"); panel.setBorder(border);//from ww w . j a v a 2 s . c om final ButtonGroup group = new ButtonGroup(); AbstractButton abstract1 = new JRadioButton("One"); panel.add(abstract1); group.add(abstract1); AbstractButton abstract2 = new JRadioButton("Two"); panel.add(abstract2); group.add(abstract2); AbstractButton abstract3 = new JRadioButton("Three"); panel.add(abstract3); group.add(abstract3); AbstractButton abstract4 = new JRadioButton("Four"); panel.add(abstract4); group.add(abstract4); AbstractButton abstract5 = new JRadioButton("Five"); panel.add(abstract5); group.add(abstract5); ActionListener aListener = new ActionListener() { public void actionPerformed(ActionEvent event) { Enumeration elements = group.getElements(); while (elements.hasMoreElements()) { AbstractButton button = (AbstractButton) elements.nextElement(); if (button.isSelected()) { System.out.println("The winner is: " + button.getText()); break; } } group.setSelected(null, true); } }; JButton button = new JButton("Show Selected"); button.addActionListener(aListener); Container container = frame.getContentPane(); container.add(panel, BorderLayout.CENTER); container.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Command: " + e.getActionCommand()); int modifiers = e.getModifiers(); System.out.println("\tALT : " + checkMod(modifiers, ActionEvent.ALT_MASK)); System.out.println("\tCTRL : " + checkMod(modifiers, ActionEvent.CTRL_MASK)); System.out.println("\tMETA : " + checkMod(modifiers, ActionEvent.META_MASK)); System.out.println("\tSHIFT: " + checkMod(modifiers, ActionEvent.SHIFT_MASK)); Object source = e.getSource(); if (source instanceof JComboBox) { JComboBox jb = (JComboBox) source; System.out.println("Combo: " + jb.getSelectedItem()); }// www . jav a2 s .co m } private boolean checkMod(int modifiers, int mask) { return ((modifiers & mask) == mask); } }; String flavors[] = { "Item 1", "Item 2", "Item 3" }; JComboBox jc = new JComboBox(flavors); jc.setMaximumRowCount(4); jc.setEditable(true); jc.addActionListener(listener); contentPane.add(jc, BorderLayout.NORTH); JButton b = new JButton("Button!"); b.addActionListener(listener); contentPane.add(b, BorderLayout.CENTER); JPanel panel = new JPanel(); JLabel label = new JLabel("Label 1: "); JTextField text = new JTextField("Type your text", 15); text.addActionListener(listener); label.setDisplayedMnemonic(KeyEvent.VK_1); label.setLabelFor(text); panel.add(label); panel.add(text); contentPane.add(panel, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:ASelectedButton.java
public static void main(String args[]) { JFrame frame = new JFrame("Radio Buttons"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new GridLayout(0, 1)); Border border = BorderFactory.createTitledBorder("Options"); panel.setBorder(border);//w w w . ja va2 s. co m final ButtonGroup group = new ButtonGroup(); AbstractButton abstract1 = new JRadioButton("One"); panel.add(abstract1); group.add(abstract1); AbstractButton abstract2 = new JRadioButton("Two"); panel.add(abstract2); group.add(abstract2); AbstractButton abstract3 = new JRadioButton("Three"); panel.add(abstract3); group.add(abstract3); AbstractButton abstract4 = new JRadioButton("Four"); panel.add(abstract4); group.add(abstract4); AbstractButton abstract5 = new JRadioButton("Five"); panel.add(abstract5); group.add(abstract5); ActionListener aListener = new ActionListener() { public void actionPerformed(ActionEvent event) { Enumeration elements = group.getElements(); while (elements.hasMoreElements()) { AbstractButton button = (AbstractButton) elements.nextElement(); if (button.isSelected()) { System.out.println("The winner is: " + button.getText()); break; } } group.setSelected(null, true); } }; JToggleButton button = new JToggleButton("Show Selected"); button.addActionListener(aListener); Container container = frame.getContentPane(); container.add(panel, BorderLayout.CENTER); container.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:ActionTest.java
public static void main(String args[]) { JFrame frame = new JFrame(); Container contentPane = frame.getContentPane(); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Command: " + e.getActionCommand()); System.out.println("Modifiers: "); int modifiers = e.getModifiers(); System.out.println("\tALT : " + checkMod(modifiers, ActionEvent.ALT_MASK)); System.out.println("\tCTRL : " + checkMod(modifiers, ActionEvent.CTRL_MASK)); System.out.println("\tMETA : " + checkMod(modifiers, ActionEvent.META_MASK)); System.out.println("\tSHIFT: " + checkMod(modifiers, ActionEvent.SHIFT_MASK)); Object source = e.getSource(); if (source instanceof JComboBox) { JComboBox jb = (JComboBox) source; System.out.println("Combo: " + jb.getSelectedItem()); }// w w w. j ava 2 s .com } private boolean checkMod(int modifiers, int mask) { return ((modifiers & mask) == mask); } }; String flavors[] = { "Item 1", "Item 2", "Item 3" }; JComboBox jc = new JComboBox(flavors); jc.setMaximumRowCount(4); jc.setEditable(true); jc.addActionListener(listener); contentPane.add(jc, BorderLayout.NORTH); JButton b = new JButton("Button!"); b.addActionListener(listener); contentPane.add(b, BorderLayout.CENTER); JPanel panel = new JPanel(); JLabel label = new JLabel("Label 1: "); JTextField text = new JTextField("Type your text", 15); text.addActionListener(listener); label.setDisplayedMnemonic(KeyEvent.VK_1); label.setLabelFor(text); panel.add(label); panel.add(text); contentPane.add(panel, BorderLayout.SOUTH); frame.pack(); frame.show(); }
From source file:ProgressBarStep.java
public static void main(String args[]) { // Initialize final JProgressBar aJProgressBar = new JProgressBar(0, 50); aJProgressBar.setStringPainted(true); final JButton aJButton = new JButton("Start"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { aJButton.setEnabled(false);//w ww . j a va 2 s .c o m Thread stepper = new BarThread(aJProgressBar); stepper.start(); } }; aJButton.addActionListener(actionListener); String title = (args.length == 0 ? "Stepping Progress" : args[0]); JFrame theFrame = new JFrame(title); theFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = theFrame.getContentPane(); contentPane.add(aJProgressBar, BorderLayout.NORTH); contentPane.add(aJButton, BorderLayout.SOUTH); theFrame.setSize(300, 200); theFrame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) { final JFrame frame = new JFrame("Change Look"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Object source = actionEvent.getSource(); String lafClassName = null; if (source instanceof JComboBox) { JComboBox comboBox = (JComboBox) source; lafClassName = (String) comboBox.getSelectedItem(); } else if (source instanceof JButton) { lafClassName = actionEvent.getActionCommand(); }/*from w w w . j a v a2 s. co m*/ if (lafClassName != null) { final String finalLafClassName = lafClassName; try { UIManager.setLookAndFeel(finalLafClassName); SwingUtilities.updateComponentTreeUI(frame); } catch (Exception exception) { JOptionPane.showMessageDialog(frame, "Can't change look and feel", "Invalid PLAF", JOptionPane.ERROR_MESSAGE); } } } }; UIManager.LookAndFeelInfo looks[] = UIManager.getInstalledLookAndFeels(); DefaultComboBoxModel model = new DefaultComboBoxModel(); JComboBox comboBox = new JComboBox(model); JPanel panel = new JPanel(); for (int i = 0, n = looks.length; i < n; i++) { JButton button = new JButton(looks[i].getName()); model.addElement(looks[i].getClassName()); button.setActionCommand(looks[i].getClassName()); button.addActionListener(actionListener); panel.add(button); } comboBox.addActionListener(actionListener); frame.add(comboBox, BorderLayout.NORTH); frame.add(panel, BorderLayout.SOUTH); frame.setSize(350, 150); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Button Sample"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Select Me"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println("I was selected."); }//from w ww. ja v a2 s . c o m }; MouseListener mouseListener = new MouseAdapter() { public void mousePressed(MouseEvent mouseEvent) { int modifiers = mouseEvent.getModifiers(); if ((modifiers & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) { // Mask may not be set properly prior to Java 2 // See SwingUtilities.isLeftMouseButton() for workaround System.out.println("Left button pressed."); } if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) { System.out.println("Middle button pressed."); } if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { System.out.println("Right button pressed."); } } public void mouseReleased(MouseEvent mouseEvent) { if (SwingUtilities.isLeftMouseButton(mouseEvent)) { System.out.println("Left button released."); } if (SwingUtilities.isMiddleMouseButton(mouseEvent)) { System.out.println("Middle button released."); } if (SwingUtilities.isRightMouseButton(mouseEvent)) { System.out.println("Right button released."); } System.out.println(); } }; button.addActionListener(actionListener); button.addMouseListener(mouseListener); Container contentPane = frame.getContentPane(); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 100); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JToggleButton toggleButton = new JToggleButton("Selected"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { AbstractButton abstractButton = (AbstractButton) actionEvent.getSource(); boolean selected = abstractButton.getModel().isSelected(); System.out.println("Action - selected=" + selected + "\n"); }/*from w w w. ja v a 2 s.c o m*/ }; ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { AbstractButton abstractButton = (AbstractButton) changeEvent.getSource(); ButtonModel buttonModel = abstractButton.getModel(); boolean armed = buttonModel.isArmed(); boolean pressed = buttonModel.isPressed(); boolean selected = buttonModel.isSelected(); System.out.println("Changed: " + armed + "/" + pressed + "/" + selected); } }; ItemListener itemListener = new ItemListener() { public void itemStateChanged(ItemEvent itemEvent) { int state = itemEvent.getStateChange(); if (state == ItemEvent.SELECTED) { System.out.println("Selected"); } else { System.out.println("Deselected"); } } }; toggleButton.addActionListener(actionListener); toggleButton.addChangeListener(changeListener); toggleButton.addItemListener(itemListener); frame.add(toggleButton, BorderLayout.NORTH); JToggleButton toggleButton2 = new JToggleButton("Focused"); frame.add(toggleButton2, BorderLayout.CENTER); JToggleButton toggleButton3 = new JToggleButton("Not Selected"); frame.add(toggleButton3, BorderLayout.SOUTH); frame.setSize(300, 125); frame.setVisible(true); }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame("Clip Image"); Container contentPane = frame.getContentPane(); final Clipboard clipboard = frame.getToolkit().getSystemClipboard(); Icon icon = new ImageIcon("jaeger.jpg"); final JLabel label = new JLabel(icon); label.setTransferHandler(new ImageSelection()); JScrollPane pane = new JScrollPane(label); contentPane.add(pane, BorderLayout.CENTER); JButton copy = new JButton("Copy"); copy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { TransferHandler handler = label.getTransferHandler(); handler.exportToClipboard(label, clipboard, TransferHandler.COPY); }/*from w w w . j a va 2 s . co m*/ }); JButton clear = new JButton("Clear"); clear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { label.setIcon(null); } }); JButton paste = new JButton("Paste"); paste.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Transferable clipData = clipboard.getContents(clipboard); if (clipData != null) { if (clipData.isDataFlavorSupported(DataFlavor.imageFlavor)) { TransferHandler handler = label.getTransferHandler(); handler.importData(label, clipData); } } } }); JPanel p = new JPanel(); p.add(copy); p.add(clear); p.add(paste); contentPane.add(p, BorderLayout.SOUTH); frame.setSize(300, 300); frame.show(); }