List of usage examples for javax.swing BoxLayout X_AXIS
int X_AXIS
To view the source code for javax.swing BoxLayout X_AXIS.
Click Source Link
From source file:BoxLayoutGlueStrutCompare.java
public BoxLayoutGlueStrutCompare() { JPanel p = new JPanel(new GridLayout(3, 1)); JPanel p1 = new JPanel(); Box box1 = new Box(BoxLayout.X_AXIS); box1.add(Box.createHorizontalGlue()); box1.add(new JButton("glue-strut")); box1.add(Box.createHorizontalStrut(15)); box1.add(new JButton("strut-glue")); box1.add(Box.createHorizontalGlue()); p1.add(box1);/*from w ww . ja v a2s .c o m*/ p1.setBorder(BorderFactory.createRaisedBevelBorder()); JPanel p2 = new JPanel(); Box box2 = new Box(BoxLayout.X_AXIS); box2.add(Box.createHorizontalStrut(25)); box2.add(new JButton("strut-glue")); box2.add(Box.createHorizontalGlue()); box2.add(new JButton("glue-strut")); box2.add(Box.createHorizontalStrut(25)); p2.add(box2); p2.setBorder(BorderFactory.createRaisedBevelBorder()); JPanel p3 = new JPanel(); Box box3 = new Box(BoxLayout.X_AXIS); box3.add(Box.createHorizontalStrut(25)); box3.add(new JButton("strut-glue")); box3.add(Box.createHorizontalGlue()); box3.add(new JButton("glue-glue")); box3.add(Box.createHorizontalGlue()); p3.add(box3); p3.setBorder(BorderFactory.createRaisedBevelBorder()); p.add(p1); p.add(p2); p.add(p3); getContentPane().add(p); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pack(); }
From source file:Main.java
/** * Initialises the {@link JDialog} for the {@link JComponent}. * //from w w w . j a v a 2 s .c om * @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 ww .j a v a 2s .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
/** Make a JPanel with a horizontal {@link BoxLayout}. */ public static JPanel makeHorizontalBoxPanel() { JPanel result = new JPanel(); result.setLayout(new BoxLayout(result, BoxLayout.X_AXIS)); return result; }
From source file:Main.java
public Main(int axis) { super(BoxLayout.Y_AXIS); container = new Box(axis); container.setAlignmentX(Box.LEFT_ALIGNMENT); add(container);//w w w .j a v a 2 s.c om JTextArea text = new JTextArea(); container.add(new JScrollPane(text)); JButton split = new JButton("Split"); split.setAlignmentX(Box.LEFT_ALIGNMENT); split.addActionListener(e -> { JTextArea t = new JTextArea(); container.add(new JScrollPane(t)); revalidate(); }); add(split); JButton axisChanger = new JButton("Change Axis"); axisChanger.setAlignmentX(Box.LEFT_ALIGNMENT); axisChanger.addActionListener(e -> { Box newContainer; if (((BoxLayout) container.getLayout()).getAxis() == BoxLayout.X_AXIS) { newContainer = Box.createVerticalBox(); } else { newContainer = Box.createHorizontalBox(); } for (Component c : container.getComponents()) { container.remove(c); newContainer.add(c); } remove(container); add(newContainer, 0); container = newContainer; container.setAlignmentX(Box.LEFT_ALIGNMENT); revalidate(); }); add(axisChanger); }
From source file:MainClass.java
public MainClass() { Container cp = new Box(BoxLayout.X_AXIS); setContentPane(cp);/*from www. j ava2 s . c o m*/ JPanel firstPanel = new JPanel(); propertyComboBox = new JComboBox(); propertyComboBox.addItem("text"); propertyComboBox.addItem("font"); propertyComboBox.addItem("background"); propertyComboBox.addItem("foreground"); firstPanel.add(propertyComboBox); cp.add(firstPanel); cp.add(Box.createGlue()); tf = new JTextField("Hello"); tf.setForeground(Color.RED); tf.setDragEnabled(true); cp.add(tf); cp.add(Box.createGlue()); l = new JLabel("Hello"); l.setBackground(Color.YELLOW); cp.add(l); cp.add(Box.createGlue()); JSlider stryder = new JSlider(SwingConstants.VERTICAL); stryder.setMinimum(10); stryder.setValue(14); stryder.setMaximum(72); stryder.setMajorTickSpacing(10); stryder.setPaintTicks(true); cp.add(stryder); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 300); setMyTransferHandlers((String) propertyComboBox.getSelectedItem()); MouseListener myDragListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, e, TransferHandler.COPY); } }; l.addMouseListener(myDragListener); propertyComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ce) { JComboBox bx = (JComboBox) ce.getSource(); String prop = (String) bx.getSelectedItem(); setMyTransferHandlers(prop); } }); tf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JTextField jtf = (JTextField) evt.getSource(); String fontName = jtf.getText(); Font font = new Font(fontName, Font.BOLD, 18); tf.setFont(font); } }); stryder.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { JSlider sl = (JSlider) evt.getSource(); Font oldf = tf.getFont(); Font newf = oldf.deriveFont((float) sl.getValue()); tf.setFont(newf); } }); }
From source file:MemComboBoxDemo.java
public MemComboBoxDemo() { super();//from w ww . j a v a 2 s . c om setSize(300, 100); getContentPane().setLayout(new BorderLayout()); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.add(new JLabel("Address")); urlComboBox.load("addresses.dat"); ComboBoxListener lst = new ComboBoxListener(); urlComboBox.addActionListener(lst); MemComboAgent agent = new MemComboAgent(urlComboBox); p.add(urlComboBox); getContentPane().add(p, BorderLayout.NORTH); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { urlComboBox.save("addresses.dat"); System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); urlComboBox.grabFocus(); }
From source file:PlotsBuilding.PlotPanel.java
public PlotPanel(ArrayList<PlotsData> plotscollection, Plotcr frame) { pointsPanel = new JPanel(); pointsPanel.setLayout(new BoxLayout(pointsPanel, BoxLayout.X_AXIS)); cursorInfo = new JTextArea(2, 10); cursorInfo.setVisible(true);// w ww. ja va 2s .co m chartPanel = new ChartPanel(fillCollection(plotscollection)); chartPanel.addChartMouseListener(new MyChartMouseListener()); chartPanel.setPreferredSize(new Dimension(800, 450)); pointsPanel.setMaximumSize(new Dimension(chartPanel.getWidth(), 70)); pointsPanel.add(cursorInfo); chartPanel.setBackground(Color.WHITE); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(chartPanel); add(pointsPanel); }
From source file:CommonLayouts.java
public CommonLayouts() { super("Common Layout Managers"); setSize(500, 380);// w w w . jav a2 s. c o m JPanel desktop = new JPanel(); getContentPane().add(desktop); JPanel fr1 = new JPanel(); fr1.setBorder(new TitledBorder("FlowLayout")); fr1.setLayout(new FlowLayout()); fr1.add(new JButton("1")); fr1.add(new JButton("2")); fr1.add(new JButton("3")); fr1.add(new JButton("4")); desktop.add(fr1, 0); JPanel fr2 = new JPanel(); fr2.setBorder(new TitledBorder("GridLayout")); fr2.setLayout(new GridLayout(2, 2)); fr2.add(new JButton("1")); fr2.add(new JButton("2")); fr2.add(new JButton("3")); fr2.add(new JButton("4")); desktop.add(fr2, 0); JPanel fr3 = new JPanel(); fr3.setBorder(new TitledBorder("BorderLayout")); fr3.add(new JButton("1"), BorderLayout.NORTH); fr3.add(new JButton("2"), BorderLayout.EAST); fr3.add(new JButton("3"), BorderLayout.SOUTH); fr3.add(new JButton("4"), BorderLayout.WEST); desktop.add(fr3, 0); JPanel fr4 = new JPanel(); fr4.setBorder(new TitledBorder("BoxLayout - X")); fr4.setLayout(new BoxLayout(fr4, BoxLayout.X_AXIS)); fr4.add(new JButton("1")); fr4.add(Box.createHorizontalStrut(12)); fr4.add(new JButton("2")); fr4.add(Box.createGlue()); fr4.add(new JButton("3")); fr4.add(Box.createHorizontalGlue()); fr4.add(new JButton("4")); desktop.add(fr4, 0); JPanel fr5 = new JPanel(); fr5.setBorder(new TitledBorder("BoxLayout - Y")); fr5.setLayout(new BoxLayout(fr5, BoxLayout.Y_AXIS)); fr5.add(new JButton("1")); fr5.add(Box.createVerticalStrut(10)); fr5.add(new JButton("2")); fr5.add(Box.createGlue()); fr5.add(new JButton("3")); fr5.add(Box.createVerticalGlue()); fr5.add(new JButton("4")); desktop.add(fr5, 0); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:net.ontopia.topicmaps.viz.AboutFrame.java
private Component createImagePanel() { Box main = new Box(BoxLayout.X_AXIS); Icon aboutImage = this.getAboutImage(); JLabel imageLabel;/*from ww w .j a v a 2 s . co m*/ if (aboutImage == null) imageLabel = new JLabel("Ontopia AS - The TopicMap People"); else imageLabel = new JLabel(aboutImage); main.add(imageLabel); return main; }