List of usage examples for javax.swing BoxLayout LINE_AXIS
int LINE_AXIS
To view the source code for javax.swing BoxLayout LINE_AXIS.
Click Source Link
From source file:Main.java
public static void main(String[] a) { JFrame frame = new JFrame("Alignment Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String labels[] = { "--", "----", "--------", "------------" }; JPanel container = new JPanel(); BoxLayout layout = new BoxLayout(container, BoxLayout.LINE_AXIS); container.setLayout(layout);/*from ww w . ja v a 2 s. c om*/ for (int i = 0; i < labels.length; i++) { JButton button = new JButton(labels[i]); container.add(button); } frame.add(container, BorderLayout.CENTER); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static JPanel createLineBoxLaidOutPanel() { final JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.LINE_AXIS)); return p;// w ww . j a v a2 s .com }
From source file:Main.java
public static final Component groupHorizontal(final Component... components) { return group(components, BoxLayout.LINE_AXIS); }
From source file:Main.java
public static Box createHorizBox(Component... comps) { return createBox(BoxLayout.LINE_AXIS, comps); }
From source file:components.ScrollDemo.java
public ScrollDemo() { setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); //Get the image to use. ImageIcon bee = createImageIcon("images/flyingBee.jpg"); //Create the row and column headers. columnView = new Rule(Rule.HORIZONTAL, true); rowView = new Rule(Rule.VERTICAL, true); if (bee != null) { columnView.setPreferredWidth(bee.getIconWidth()); rowView.setPreferredHeight(bee.getIconHeight()); } else {/*from www.jav a2s . c o m*/ columnView.setPreferredWidth(320); rowView.setPreferredHeight(480); } //Create the corners. JPanel buttonCorner = new JPanel(); //use FlowLayout isMetric = new JToggleButton("cm", true); isMetric.setFont(new Font("SansSerif", Font.PLAIN, 11)); isMetric.setMargin(new Insets(2, 2, 2, 2)); isMetric.addItemListener(this); buttonCorner.add(isMetric); //Set up the scroll pane. picture = new ScrollablePicture(bee, columnView.getIncrement()); JScrollPane pictureScrollPane = new JScrollPane(picture); pictureScrollPane.setPreferredSize(new Dimension(300, 250)); pictureScrollPane.setViewportBorder(BorderFactory.createLineBorder(Color.black)); pictureScrollPane.setColumnHeaderView(columnView); pictureScrollPane.setRowHeaderView(rowView); //Set the corners. //In theory, to support internationalization you would change //UPPER_LEFT_CORNER to UPPER_LEADING_CORNER, //LOWER_LEFT_CORNER to LOWER_LEADING_CORNER, and //UPPER_RIGHT_CORNER to UPPER_TRAILING_CORNER. In practice, //bug #4467063 makes that impossible (in 1.4, at least). pictureScrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, buttonCorner); pictureScrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, new Corner()); pictureScrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, new Corner()); //Put it in this panel. add(pictureScrollPane); setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); }
From source file:HtmlDemo.java
public HtmlDemo() { setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); String initialText = "<html>\n" + "Color and font test:\n" + "<ul>\n" + "<li><font color=red>red</font>\n" + "<li><font color=blue>blue</font>\n" + "<li><font color=green>green</font>\n" + "<li><font size=-2>small</font>\n" + "<li><font size=+2>large</font>\n" + "<li><i>italic</i>\n" + "<li><b>bold</b>\n" + "</ul>\n"; htmlTextArea = new JTextArea(10, 20); htmlTextArea.setText(initialText);/*from ww w. java 2 s . c o m*/ JScrollPane scrollPane = new JScrollPane(htmlTextArea); JButton changeTheLabel = new JButton("Change the label"); changeTheLabel.setMnemonic(KeyEvent.VK_C); changeTheLabel.setAlignmentX(Component.CENTER_ALIGNMENT); changeTheLabel.addActionListener(this); theLabel = new JLabel(initialText) { public Dimension getPreferredSize() { return new Dimension(200, 200); } public Dimension getMinimumSize() { return new Dimension(200, 200); } public Dimension getMaximumSize() { return new Dimension(200, 200); } }; theLabel.setVerticalAlignment(SwingConstants.CENTER); theLabel.setHorizontalAlignment(SwingConstants.CENTER); JPanel leftPanel = new JPanel(); leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS)); leftPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Edit the HTML, then click the button"), BorderFactory.createEmptyBorder(10, 10, 10, 10))); leftPanel.add(scrollPane); leftPanel.add(Box.createRigidArea(new Dimension(0, 10))); leftPanel.add(changeTheLabel); JPanel rightPanel = new JPanel(); rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.PAGE_AXIS)); rightPanel .setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("A label with HTML"), BorderFactory.createEmptyBorder(10, 10, 10, 10))); rightPanel.add(theLabel); setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); add(leftPanel); add(Box.createRigidArea(new Dimension(10, 0))); add(rightPanel); }
From source file:Main.java
public Main() { super(new BorderLayout()); listModel.addElement("A"); listModel.addElement("B"); listModel.addElement("C"); list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0);//from w ww . j ava 2s . c o m list.addListSelectionListener(this); list.setVisibleRowCount(5); JScrollPane listScrollPane = new JScrollPane(list); JButton hireButton = new JButton(addCommand); HireListener hireListener = new HireListener(hireButton); hireButton.setActionCommand(addCommand); hireButton.addActionListener(hireListener); hireButton.setEnabled(false); fireButton = new JButton(deleteCommand); fireButton.setActionCommand(deleteCommand); fireButton.addActionListener(new FireListener()); employeeName = new JTextField(10); employeeName.addActionListener(hireListener); employeeName.getDocument().addDocumentListener(hireListener); String name = listModel.getElementAt(list.getSelectedIndex()).toString(); System.out.println(name); // Create a panel that uses BoxLayout. JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.add(fireButton); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(new JSeparator(SwingConstants.VERTICAL)); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(employeeName); buttonPane.add(hireButton); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(listScrollPane, BorderLayout.CENTER); add(buttonPane, BorderLayout.PAGE_END); }
From source file:AnimatedButton.java
public AnimatedButton(String buttonText, boolean useBgImage, Color defaultForeground, boolean allowAnimate) { this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); button.setText(buttonText);//w w w. j a v a2s.c o m this.foreground = defaultForeground; this.allowAnimate = allowAnimate; setOpaque(false); add(button); if (allowAnimate) runThread.start(); }
From source file:Main.java
public Main() { super(new BorderLayout()); listModel = new DefaultListModel(); listModel.addElement("Debbie Scott"); listModel.addElement("Scott Hommel"); listModel.addElement("Sharon Zakhour"); // Create the list and put it in a scroll pane. list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0);/*from ww w . ja va 2 s. c o m*/ list.addListSelectionListener(this); list.setVisibleRowCount(5); JScrollPane listScrollPane = new JScrollPane(list); JButton hireButton = new JButton(hireString); HireListener hireListener = new HireListener(hireButton); hireButton.setActionCommand(hireString); hireButton.addActionListener(hireListener); hireButton.setEnabled(false); fireButton = new JButton(fireString); fireButton.setActionCommand(fireString); fireButton.addActionListener(new FireListener()); employeeName = new JTextField(10); employeeName.addActionListener(hireListener); employeeName.getDocument().addDocumentListener(hireListener); String name = listModel.getElementAt(list.getSelectedIndex()).toString(); // Create a panel that uses BoxLayout. JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.add(fireButton); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(new JSeparator(SwingConstants.VERTICAL)); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(employeeName); buttonPane.add(hireButton); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(listScrollPane, BorderLayout.CENTER); add(buttonPane, BorderLayout.PAGE_END); }
From source file:com.idealista.solrmeter.view.statistic.PieChartPanel.java
private Component createCustomizePanel() { JButton jButtonCustomize = new JButton(I18n.get("statistic.pieChartPanel.customize")); jButtonCustomize.addActionListener(new ActionListener() { @Override/*from www . j a v a 2 s . c o m*/ public void actionPerformed(ActionEvent e) { JDialogCustomizePieChart dialog = new JDialogCustomizePieChart(SolrMeterMain.mainFrame, timeRangeStatistic); dialog.setVisible(true); } }); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.LINE_AXIS)); panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 10)); panel.add(Box.createHorizontalGlue()); panel.add(jButtonCustomize); return panel; }