List of usage examples for javax.swing Box add
public Component add(Component comp)
From source file:StrutSample.java
public static void main(String args[]) { Box horizontalBox; JPanel panel;/*from www . j a v a 2 s . com*/ JFrame frame = new JFrame("Horizontal Strut"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(0, 1)); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(Box.createHorizontalStrut(10)); horizontalBox.add(new JButton("Left")); horizontalBox.add(new JButton("Middle")); horizontalBox.add(new JButton("Right")); panel = new JPanel(new BorderLayout()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("Beginning Strut")); contentPane.add(panel); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(new JButton("Left")); horizontalBox.add(Box.createHorizontalStrut(10)); horizontalBox.add(new JButton("Middle")); horizontalBox.add(Box.createHorizontalStrut(25)); horizontalBox.add(new JButton("Right")); panel = new JPanel(new BorderLayout()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("2 Middle Struts")); contentPane.add(panel); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(Box.createHorizontalStrut(25)); horizontalBox.add(new JButton("Left")); horizontalBox.add(new JButton("Middle")); horizontalBox.add(new JButton("Right")); horizontalBox.add(Box.createHorizontalStrut(10)); panel = new JPanel(new BorderLayout()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("Beginning/End Struts")); contentPane.add(panel); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(new JButton("Left")); horizontalBox.add(new JButton("Middle")); horizontalBox.add(new JButton("Right")); panel = new JPanel(new BorderLayout()); horizontalBox.add(Box.createHorizontalStrut(10)); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("End Strut")); contentPane.add(panel); frame.setSize(300, 300); frame.setVisible(true); }
From source file:GlueSample.java
public static void main(String args[]) { Box horizontalBox; JPanel panel;// w ww . j a v a 2 s .co m JFrame frame = new JFrame("Horizontal Glue"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(0, 1)); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(Box.createGlue()); horizontalBox.add(new JButton("Left")); horizontalBox.add(new JButton("Middle")); horizontalBox.add(new JButton("Right")); panel = new JPanel(new BorderLayout()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("Beginning Glue")); contentPane.add(panel); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(new JButton("Left")); horizontalBox.add(Box.createGlue()); horizontalBox.add(new JButton("Middle")); horizontalBox.add(Box.createGlue()); horizontalBox.add(new JButton("Right")); panel = new JPanel(new BorderLayout()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("2 Middle Glues")); contentPane.add(panel); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(Box.createGlue()); horizontalBox.add(new JButton("Left")); horizontalBox.add(new JButton("Middle")); horizontalBox.add(new JButton("Right")); horizontalBox.add(Box.createGlue()); panel = new JPanel(new BorderLayout()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("Beginning/End Glues")); contentPane.add(panel); horizontalBox = Box.createHorizontalBox(); horizontalBox.add(new JButton("Left")); horizontalBox.add(new JButton("Middle")); horizontalBox.add(new JButton("Right")); panel = new JPanel(new BorderLayout()); horizontalBox.add(Box.createGlue()); panel.add(horizontalBox); panel.setBorder(BorderFactory.createTitledBorder("End Glue")); contentPane.add(panel); frame.setSize(300, 300); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { Box box = Box.createVerticalBox(); for (int i = 1; i < 4; i++) { JPanel panel = new JPanel() { @Override/* ww w . j ava 2 s . c om*/ public Dimension getMaximumSize() { return getPreferredSize(); } }; JLabel label1 = new JLabel("Label"); JLabel label2 = new JLabel(String.valueOf(i)); panel.add(label1); panel.add(label2); box.add(panel); } JFrame frame = new JFrame(); frame.add(box); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:Main.java
/** * Places the given components in a horizontal Box with a glue at the front, * causing the components to align right. * @param components the components to add * @return the components in a horizontal box, aligned right *///w w w .j a v a 2s .c om public static Box buildRightAlignedRow(Component... components) { final Box result = Box.createHorizontalBox(); result.add(Box.createHorizontalGlue()); Arrays.stream(components).forEach(result::add); return result; }
From source file:Main.java
public static Box createBox(int axis, Component... comps) { Box r = new Box(axis); for (Component comp : comps) { r.add(comp); }/*from w ww.j a v a 2 s . c o m*/ return r; }
From source file:Main.java
/** * Places the given components in a horizontal Box with a glue at the end, * causing the components to align left. * @param components the components to add * @return the components in a horizontal Box, aligned left *///from w ww.j a va 2 s .c om public static Box buildLeftAlignedRow(Component... components) { final Box result = Box.createHorizontalBox(); Arrays.stream(components).forEach(result::add); result.add(Box.createHorizontalGlue()); return result; }
From source file:org.jdal.swing.form.FormUtils.java
/** * Create a box with an aligned component using Component constants for right, center and left. * @param c component/*from w w w. j av a2 s . c o m*/ * @param alignment aligment. * @return Box with compoenent */ public static Component newBoxForComponent(Component c, float alignment) { Box box = Box.createHorizontalBox(); if (Component.RIGHT_ALIGNMENT == alignment) { box.add(Box.createHorizontalGlue()); box.add(c); } else if (Component.CENTER_ALIGNMENT == alignment) { box.add(Box.createHorizontalGlue()); box.add(c); box.add(Box.createHorizontalGlue()); } else { // default to left box.add(c); box.add(Box.createHorizontalGlue()); } return box; }
From source file:org.swiftexplorer.gui.AboutDlg.java
public static void show(Component parent, HasLocalizedStrings stringsBundle) { URI uri = null;/* www.j ava 2 s . co m*/ try { uri = new URI("http://www.swiftexplorer.org"); } catch (URISyntaxException e) { logger.error("URL seems to be ill-formed", e); } final String buttontext = "www.swiftexplorer.org"; Box mainBox = Box.createVerticalBox(); mainBox.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 0)); StringBuilder sb = loadResource("/about.html"); JLabel label = new JLabel(sb.toString()); label.getAccessibleContext().setAccessibleDescription(getTitle(stringsBundle)); mainBox.add(label); if (uri != null) { JButton button = new JButton(); button.setText(buttontext); button.setToolTipText(uri.toString()); button.addActionListener(new OpenUrlAction(uri)); FontMetrics metrics = button.getFontMetrics(button.getFont()); if (metrics != null) button.setSize(metrics.stringWidth(buttontext), button.getHeight()); button.getAccessibleContext().setAccessibleDescription(buttontext); mainBox.add(button); } mainBox.add(Box.createVerticalStrut(10)); JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); panel.add(mainBox); JOptionPane.showMessageDialog(parent, panel, getTitle(stringsBundle), JOptionPane.INFORMATION_MESSAGE, getIcon()); }
From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.IntHistogramVisualizer.java
/** * Creates the combo box (drop-down list) to choose between visualization of the histogram as bar chart or * as a scatter plot.// w w w . j av a2s . c o m * * @param aContainer Container control, to which the combo box is to be added. * @param aSelectedIndex Which choice is to be initially selected. This parameter must have one of the * values <code>{1; 2}</code>. * @return The newly created combo box control. */ private static JComboBox addChoice(Box aContainer, int aSelectedIndex) { final String[] choices = new String[] { Messages.DI_SHOWHIST, Messages.DI_SHOWSCAT }; JComboBox choiceCombo = new JComboBox(choices); choiceCombo.setSelectedIndex(aSelectedIndex); choiceCombo.setEditable(false); JPanel choicePanel = new JPanel(); choicePanel.add(choiceCombo); aContainer.add(choicePanel); return choiceCombo; }
From source file:greenfoot.gui.export.ExportPublishPane.java
/** * Build a help box with a link to appropriate help * @return help box/* w w w . j a v a2 s. c om*/ */ private static Box getHelpBox() { Box helpBox = new Box(BoxLayout.X_AXIS); helpBox.setAlignmentX(LEFT_ALIGNMENT); JLabel helpText1 = new JLabel(helpLine1 + " ("); helpBox.add(helpText1); JLabel serverLink = new JLabel(serverURL); GreenfootUtil.makeLink(serverLink, serverURL); helpBox.add(serverLink); helpBox.add(new JLabel(")")); return helpBox; }