List of usage examples for javax.swing BoxLayout BoxLayout
@ConstructorProperties({ "target", "axis" }) public BoxLayout(Container target, int axis)
From source file:Main.java
/** * Initialises the {@link JDialog} for the {@link JComponent}. * /* w ww.j a va 2s . c o m*/ * @param dialog * @param component * @param parentComponent */ private static void initDialog(final JDialog dialog, final JComponent component, final Component parentComponent) { dialog.setResizable(true); dialog.setComponentOrientation(component.getComponentOrientation()); Container contentPane = dialog.getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.add(component, BorderLayout.CENTER); final int buttonWidth = 75; final JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(2, 4, 4, 4)); buttonPanel.add(Box.createHorizontalGlue()); @SuppressWarnings("serial") final Action closeAction = new AbstractAction("Close") { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }; final JButton button = new JButton(closeAction); fixWidth(button, buttonWidth); buttonPanel.add(button); contentPane.add(buttonPanel, BorderLayout.SOUTH); if (JDialog.isDefaultLookAndFeelDecorated()) { boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations(); if (supportsWindowDecorations) { dialog.setUndecorated(true); component.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG); } } dialog.pack(); dialog.setLocationRelativeTo(parentComponent); WindowAdapter adapter = new WindowAdapter() { // private boolean gotFocus = false; public void windowClosing(WindowEvent we) { fireAction(we.getSource(), closeAction, "close"); } }; dialog.addWindowListener(adapter); dialog.addWindowFocusListener(adapter); }
From source file:HBox.java
public HBox() { super("Horizontal Box Test Frame"); setSize(200, 100);//from w w w. j a v a2s .co m Panel box = new Panel(); // Use BoxLayout.Y_AXIS below if you want a vertical box box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS)); setContentPane(box); for (int i = 0; i < 3; i++) { Button b = new Button("B" + i); box.add(b); } setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); }
From source file:Main.java
public Main() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField field1 = new JTextField("Life's a drag", 20); JTextField field2 = new JTextField("and then you drop", 20); field1.setDragEnabled(true);// ww w.j a va 2s. c o m field2.setDragEnabled(true); Container content = getContentPane(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.add(field1); content.add(field2); pack(); }
From source file:Main.java
public Main() { JPanel panel = new JPanel(); BoxLayout boxLayout = new BoxLayout(panel, BoxLayout.PAGE_AXIS); panel.setLayout(boxLayout);/*from w w w . ja va 2 s . co m*/ for (int i = 0; i < 40; i++) { panel.add(new JButton("Button " + i)); } buttons = panel.getComponents(); activeComponent = buttons[index]; final JScrollPane scroll = new JScrollPane(panel); Timer timer = new Timer(500, new ActionListener() { public void actionPerformed(ActionEvent e) { ((JButton) activeComponent).setForeground(Color.BLACK); if (index >= buttons.length - 1) { index = 0; } else { index++; } activeComponent = buttons[index]; ((JButton) activeComponent).setForeground(Color.red); setView(scroll, activeComponent); System.out.println(((JButton) activeComponent).getActionCommand()); } }); timer.start(); scroll.setPreferredSize(new Dimension(200, 300)); JFrame frame = new JFrame(); frame.add(scroll); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); }
From source file:DragDropText.java
public DragDropText() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField field1 = new JTextField("Life's a drag", 20); JTextField field2 = new JTextField("and then you drop", 20); field1.setDragEnabled(true);// w ww . j a v a2 s . c o m field2.setDragEnabled(true); Container content = getContentPane(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.add(field1); content.add(field2); pack(); }
From source file:TextSlider.java
public TextSlider() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); textField = new JTextField(); scrollBar = new JScrollBar(JScrollBar.HORIZONTAL); BoundedRangeModel brm = textField.getHorizontalVisibility(); scrollBar.setModel(brm);// www .j av a 2s . com add(textField); add(scrollBar); }
From source file:FramewithComponents.java
public FramewithComponents() { super("JLayeredPane Demo"); setSize(256, 256);//from w ww .j a v a 2 s . c o m JPanel content = new JPanel(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.setOpaque(false); JLabel label1 = new JLabel("Username:"); label1.setForeground(Color.white); content.add(label1); JTextField field = new JTextField(15); content.add(field); JLabel label2 = new JLabel("Password:"); label2.setForeground(Color.white); content.add(label2); JPasswordField fieldPass = new JPasswordField(15); content.add(fieldPass); getContentPane().setLayout(new FlowLayout()); getContentPane().add(content); ((JPanel) getContentPane()).setOpaque(false); ImageIcon earth = new ImageIcon("largeJava2sLogo.png"); JLabel backlabel = new JLabel(earth); getLayeredPane().add(backlabel, new Integer(Integer.MIN_VALUE)); backlabel.setBounds(0, 0, earth.getIconWidth(), earth.getIconHeight()); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(l); setVisible(true); }
From source file:Main.java
public JPanel createUI() { intro.setLabelFor(name);/* w ww . j av a2 s .c o m*/ final JButton button = new JButton("Pick a new name..."); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20)); intro.setAlignmentX(JComponent.CENTER_ALIGNMENT); name.setAlignmentX(JComponent.CENTER_ALIGNMENT); button.setAlignmentX(JComponent.CENTER_ALIGNMENT); panel.add(intro); panel.add(Box.createVerticalStrut(5)); panel.add(name); panel.add(Box.createRigidArea(new Dimension(150, 10))); panel.add(button); return panel; }
From source file:Main.java
public GameFrame() { setSize(300, 300);//from w w w . j a v a2 s .com setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); if (FULLSCREEN_SUPPORTED) { fsButton.addActionListener(e -> toggleFullscreen()); add(fsButton); } else { add(new JLabel("Fullscreen mode is not supported on this device")); } }
From source file:Main.java
public void createUI() { JPanel borderPanel = new JPanel(new BorderLayout()); JLabel northLabel = new JLabel("Nawth"); borderPanel.add(northLabel, BorderLayout.NORTH); JComboBox southCombo = new JComboBox(); borderPanel.add(southCombo, BorderLayout.SOUTH); JPanel centerPanel = new JPanel(); centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.PAGE_AXIS)); JComboBox firstCombo = new JComboBox(); centerPanel.add(firstCombo);//w w w .j a v a2 s . c o m centerPanel.add(Box.createVerticalGlue()); JPanel centerPanelConstrain = new JPanel(new GridBagLayout()); centerPanelConstrain.add(centerPanel); borderPanel.add(centerPanelConstrain, BorderLayout.CENTER); getContentPane().add(borderPanel); pack(); }