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:FactoryDemo.java
public static void main(String argv[]) { JFrame f = new JFrame("FactoryDemo"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(demo1(), BorderLayout.NORTH); f.getContentPane().add(demo2(), BorderLayout.SOUTH); f.setSize(240, 160);// www .ja v a2s.com f.setVisible(true); }
From source file:DragImage.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()); MouseListener mouseListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent comp = (JComponent) e.getSource(); TransferHandler handler = comp.getTransferHandler(); handler.exportAsDrag(comp, e, TransferHandler.COPY); }/* w w w . j a v a2 s.co m*/ }; label.addMouseListener(mouseListener); 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); } }); JButton clear = new JButton("Clear"); clear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { label.setIcon(null); } }); clear.setTransferHandler(new TransferHandler("text")); mouseListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent comp = (JComponent) e.getSource(); TransferHandler handler = comp.getTransferHandler(); handler.exportAsDrag(comp, e, TransferHandler.COPY); } }; clear.addMouseListener(mouseListener); 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); JTextField tf = new JTextField(); tf.setDragEnabled(true); contentPane.add(tf, BorderLayout.NORTH); frame.setSize(300, 300); frame.show(); }
From source file:MouseDrag.java
public static void main(String[] av) { JFrame f = new JFrame("Mouse Dragger"); Container cp = f.getContentPane(); if (av.length < 1) { System.err.println("Usage: MouseDrag imagefile"); System.exit(1);/* www . j a v a2 s. c om*/ } Image im = Toolkit.getDefaultToolkit().getImage(av[0]); // create a MouseDrag object MouseDrag j = new MouseDrag(im); cp.setLayout(new BorderLayout()); cp.add(BorderLayout.NORTH, new Label("Hello, and welcome to the world of Java")); cp.add(BorderLayout.CENTER, j); cp.add(BorderLayout.SOUTH, status = new Label()); status.setSize(f.getSize().width, status.getSize().height); f.pack(); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:com.adito.upgrade.Upgrade.java
/** * @param args//w ww .j a v a 2s . co m * @throws Exception on any error */ public static void main(String[] args) throws Exception { boolean gui = System.getProperty("os.name").toLowerCase().startsWith("windows") || System.getenv("DISPLAY") != null; if (args.length == 2 || !gui) { Upgrader upgrader = new CommandLineUpgrader(args); upgrader.upgrade(); } else { JFrame f = new JFrame("0.1.16 to 0.2.5+ Upgrader"); final Upgrader upgrader = new GUIUpgrader(); f.setIconImage(new ImageIcon(Upgrade.class.getResource("upgrader-32x32.png")).getImage()); f.getContentPane().setLayout(new BorderLayout()); f.getContentPane().add((JPanel) upgrader, BorderLayout.CENTER); f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); JPanel bp = new JPanel(new FlowLayout(FlowLayout.RIGHT)); final JButton start = new JButton("Start"); ; final JButton close = new JButton("Close"); start.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { start.setEnabled(false); close.setEnabled(false); upgrader.upgrade(); } catch (Exception ex) { upgrader.error("Failed to upgrade.", ex); } finally { close.setEnabled(true); } } }); close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (close.isEnabled()) System.exit(0); } }); bp.add(start); bp.add(close); f.getContentPane().add(bp, BorderLayout.SOUTH); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { if (close.isEnabled()) System.exit(0); } }); f.setSize(new Dimension(480, 460)); UIUtil.positionComponent(SwingConstants.CENTER, f); f.setVisible(true); } }
From source file:Main.java
public static void main(String args[]) { JFrame frame = new JFrame(); final JFormattedTextField textField1 = new JFormattedTextField(new Float(10.01)); textField1.setFormatterFactory(new AbstractFormatterFactory() { @Override//from w w w. ja v a 2 s . c o m public AbstractFormatter getFormatter(JFormattedTextField tf) { NumberFormat format = DecimalFormat.getInstance(); format.setMinimumFractionDigits(2); format.setMaximumFractionDigits(2); format.setRoundingMode(RoundingMode.HALF_UP); InternationalFormatter formatter = new InternationalFormatter(format); formatter.setAllowsInvalid(false); formatter.setMinimum(0.0); formatter.setMaximum(1000.00); return formatter; } }); Map attributes = (new Font("Serif", Font.BOLD, 16)).getAttributes(); attributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); final JFormattedTextField textField2 = new JFormattedTextField(new Float(10.01)); textField2.setFormatterFactory(new AbstractFormatterFactory() { @Override public AbstractFormatter getFormatter(JFormattedTextField tf) { NumberFormat format = DecimalFormat.getInstance(); format.setMinimumFractionDigits(2); format.setMaximumFractionDigits(2); format.setRoundingMode(RoundingMode.HALF_UP); InternationalFormatter formatter = new InternationalFormatter(format); formatter.setAllowsInvalid(false); formatter.setMinimum(0.0); formatter.setMaximum(1000.00); return formatter; } }); textField2.getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } @Override public void insertUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } @Override public void removeUpdate(DocumentEvent documentEvent) { printIt(documentEvent); } private void printIt(DocumentEvent documentEvent) { DocumentEvent.EventType type = documentEvent.getType(); double t1a1 = (((Number) textField2.getValue()).doubleValue()); if (t1a1 > 100) { textField2.setFont(new Font(attributes)); textField2.setForeground(Color.red); } else { textField2.setFont(new Font("Serif", Font.BOLD, 16)); textField2.setForeground(Color.black); } } }); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(textField1, BorderLayout.NORTH); frame.add(textField2, BorderLayout.SOUTH); frame.setVisible(true); frame.pack(); }
From source file:MouseDragClip.java
public static void main(String[] av) { JFrame f = new JFrame("Mouse Dragger"); Container cp = f.getContentPane(); if (av.length < 1) { System.err.println("Usage: MouseDragClip imagefile"); System.exit(1);//from w w w. j a v a 2s. c o m } Image im = Toolkit.getDefaultToolkit().getImage(av[0]); // create a MouseDragClip object MouseDragClip j = new MouseDragClip(im); cp.setLayout(new BorderLayout()); cp.add(BorderLayout.NORTH, new Label("Hello, and welcome to the world of Java")); cp.add(BorderLayout.CENTER, j); cp.add(BorderLayout.SOUTH, status = new Label()); status.setSize(f.getSize().width, status.getSize().height); f.pack(); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:MessagePopup.java
public static void main(String args[]) { JFrame frame = new JFrame("Message Popup"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("Pop it"); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Component source = (Component) actionEvent.getSource(); /*/* w ww. j a v a2 s . c om*/ * // String msg = "this is a really long message this is a * really long message this is a really long message this is a * really long message this is a really long message this is a * really long message this is a really long message"; String * msg = " <html>this is a really long message <br> this is a * really long message this is a really long message this is a * really long message this is a really long message this is a * really long message this is a really long message"; * JOptionPane.showMessageDialog(source, msg); JOptionPane * optionPane = OptionPaneUtils.getNarrowOptionPane(72); * optionPane.setMessage(msg); * optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); * JDialog dialog = optionPane.createDialog(source, "Width 72"); * dialog.show(); int selection = * OptionPaneUtils.getSelection(optionPane); * JOptionPane.showMessageDialog(source, msg); String * multiLineMsg[] = {"Hello", "World"}; * JOptionPane.showMessageDialog(source, multiLineMsg); * * Object complexMsg[] = {"Above Message", new * DiamondIcon(Color.red), new JButton ("Hello"), new JSlider(), * new DiamondIcon(Color.blue), "Below Message"}; * JOptionPane.showInputDialog(source, complexMsg); JOptionPane * optionPane = new JOptionPane(); JSlider slider = * OptionPaneUtils.getSlider(optionPane); * optionPane.setMessage(new Object[] {"Select a value: " , * slider}); * optionPane.setMessageType(JOptionPane.QUESTION_MESSAGE); * optionPane.setOptionType(JOptionPane.OK_CANCEL_OPTION); * JDialog dialog = optionPane.createDialog(source, "My * Slider"); dialog.show(); System.out.println ("Input: " + * optionPane.getInputValue()); */ JOptionPane optionPane = new JOptionPane(); optionPane.setMessage("I got an icon and a text label"); optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); Icon icon = new DiamondIcon(Color.blue); JButton jButton = OptionPaneUtils.getButton(optionPane, "OK", icon); optionPane.setOptions(new Object[] { jButton }); JDialog dialog = optionPane.createDialog(source, "Icon/Text Button"); dialog.show(); } }; button.addActionListener(actionListener); Container contentPane = frame.getContentPane(); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }
From source file:ParenMatcher.java
public static void main(String[] args) { JFrame frame = new JFrame("ParenMatcher"); final ParenMatcher matcher = new ParenMatcher(); matcher.setText("int fact(int n) {\n" + " if (n <= 1) return 1;\n" + " return(n * fact(n-1));\n" + "}\n"); frame.getContentPane().add(new JScrollPane(matcher), BorderLayout.CENTER); JButton matchButton = new JButton("match parens"); matchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { matcher.run();//from www .j av a 2 s . c o m } }); frame.getContentPane().add(matchButton, BorderLayout.SOUTH); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(200, 150); frame.setVisible(true); }
From source file:OverlaySample.java
public static void main(String args[]) { ActionListener generalActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { JComponent comp = (JComponent) actionEvent.getSource(); System.out.println(actionEvent.getActionCommand() + ": " + comp.getBounds()); }//from w ww. jav a 2 s. co m }; ActionListener sizingActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { setupButtons(actionEvent.getActionCommand()); } }; JFrame frame = new JFrame("Overlay Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); LayoutManager overlay = new OverlayLayout(panel); panel.setLayout(overlay); Object settings[][] = { { "Small", new Dimension(25, 25), Color.white }, { "Medium", new Dimension(50, 50), Color.gray }, { "Large", new Dimension(100, 100), Color.black } }; JButton buttons[] = { smallButton, mediumButton, largeButton }; for (int i = 0, n = settings.length; i < n; i++) { JButton button = buttons[i]; button.addActionListener(generalActionListener); button.setActionCommand((String) settings[i][0]); button.setMaximumSize((Dimension) settings[i][1]); button.setBackground((Color) settings[i][2]); panel.add(button); } setupButtons(SET_CENTRAL); JPanel actionPanel = new JPanel(); actionPanel.setBorder(BorderFactory.createTitledBorder("Change Alignment")); String actionSettings[] = { SET_MINIMUM, SET_MAXIMUM, SET_CENTRAL, SET_MIXED }; for (int i = 0, n = actionSettings.length; i < n; i++) { JButton button = new JButton(actionSettings[i]); button.addActionListener(sizingActionListener); actionPanel.add(button); } Container contentPane = frame.getContentPane(); contentPane.add(panel, BorderLayout.CENTER); contentPane.add(actionPanel, BorderLayout.SOUTH); frame.setSize(400, 300); frame.setVisible(true); }
From source file:GroupActionRadio.java
public static void main(String args[]) { String title = (args.length == 0 ? "Grouping Example" : args[0]); JFrame frame = new JFrame(title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Slice Parts ActionListener sliceActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { AbstractButton aButton = (AbstractButton) actionEvent.getSource(); System.out.println("Selected: " + aButton.getText()); }/* ww w.ja v a 2s. c o m*/ }; Container sliceContainer = RadioButtonUtils.createRadioButtonGrouping(sliceOptions, "Slice Count", sliceActionListener); // Crust Parts ActionListener crustActionListener = new ActionListener() { String lastSelected; public void actionPerformed(ActionEvent actionEvent) { AbstractButton aButton = (AbstractButton) actionEvent.getSource(); String label = aButton.getText(); String msgStart; if (label.equals(lastSelected)) { msgStart = "Reselected: "; } else { msgStart = "Selected: "; } lastSelected = label; System.out.println(msgStart + label); } }; ItemListener itemListener = new ItemListener() { String lastSelected; public void itemStateChanged(ItemEvent itemEvent) { AbstractButton aButton = (AbstractButton) itemEvent.getSource(); int state = itemEvent.getStateChange(); String label = aButton.getText(); String msgStart; if (state == ItemEvent.SELECTED) { if (label.equals(lastSelected)) { msgStart = "Reselected -> "; } else { msgStart = "Selected -> "; } lastSelected = label; } else { msgStart = "Deselected -> "; } System.out.println(msgStart + label); } }; ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent changEvent) { AbstractButton aButton = (AbstractButton) changEvent.getSource(); ButtonModel aModel = aButton.getModel(); boolean armed = aModel.isArmed(); boolean pressed = aModel.isPressed(); boolean selected = aModel.isSelected(); System.out.println("Changed: " + armed + "/" + pressed + "/" + selected); } }; final Container crustContainer = RadioButtonUtils.createRadioButtonGrouping(crustOptions, "Crust Type", crustActionListener, itemListener, changeListener); // Button Parts ActionListener buttonActionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { Enumeration selected = RadioButtonUtils.getSelectedElements(crustContainer); while (selected.hasMoreElements()) { System.out.println("Selected -> " + selected.nextElement()); } } }; JButton button = new JButton("Order Pizza"); button.addActionListener(buttonActionListener); Container contentPane = frame.getContentPane(); contentPane.add(sliceContainer, BorderLayout.WEST); contentPane.add(crustContainer, BorderLayout.EAST); contentPane.add(button, BorderLayout.SOUTH); frame.setSize(300, 200); frame.setVisible(true); }