List of usage examples for javax.swing Box add
public Component add(Component comp)
From source file:sim.util.media.chart.XYChartGenerator.java
protected void buildGlobalAttributes(LabelledList list) { // create the chart ((XYPlot) (chart.getPlot())).setDomainGridlinesVisible(false); ((XYPlot) (chart.getPlot())).setRangeGridlinesVisible(false); ((XYPlot) (chart.getPlot())).setDomainGridlinePaint(new Color(200, 200, 200)); ((XYPlot) (chart.getPlot())).setRangeGridlinePaint(new Color(200, 200, 200)); xLabel = new PropertyField() { public String newValue(String newValue) { setXAxisLabel(newValue);//from w w w . j a v a 2 s.co m getChartPanel().repaint(); return newValue; } }; xLabel.setValue(getXAxisLabel()); list.add(new JLabel("X Label"), xLabel); yLabel = new PropertyField() { public String newValue(String newValue) { setYAxisLabel(newValue); getChartPanel().repaint(); return newValue; } }; yLabel.setValue(getYAxisLabel()); list.add(new JLabel("Y Label"), yLabel); xLog = new JCheckBox(); xLog.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (xLog.isSelected()) { LogarithmicAxis logAxis = new LogarithmicAxis(xLabel.getValue()); logAxis.setStrictValuesFlag(false); chart.getXYPlot().setDomainAxis(logAxis); } else chart.getXYPlot().setDomainAxis(new NumberAxis(xLabel.getValue())); } }); yLog = new JCheckBox(); yLog.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (yLog.isSelected()) { LogarithmicAxis logAxis = new LogarithmicAxis(yLabel.getValue()); logAxis.setStrictValuesFlag(false); chart.getXYPlot().setRangeAxis(logAxis); } else chart.getXYPlot().setRangeAxis(new NumberAxis(yLabel.getValue())); } }); Box box = Box.createHorizontalBox(); box.add(new JLabel("X")); box.add(xLog); box.add(new JLabel(" Y")); box.add(yLog); box.add(Box.createGlue()); list.add(new JLabel("Log Axis"), box); final JCheckBox xgridlines = new JCheckBox(); xgridlines.setSelected(false); ItemListener il = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { chart.getXYPlot().setDomainGridlinesVisible(true); } else { chart.getXYPlot().setDomainGridlinesVisible(false); } } }; xgridlines.addItemListener(il); final JCheckBox ygridlines = new JCheckBox(); ygridlines.setSelected(false); il = new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { chart.getXYPlot().setRangeGridlinesVisible(true); } else { chart.getXYPlot().setRangeGridlinesVisible(false); } } }; ygridlines.addItemListener(il); box = Box.createHorizontalBox(); box.add(new JLabel("X")); box.add(xgridlines); box.add(new JLabel(" Y")); box.add(ygridlines); box.add(Box.createGlue()); list.add(new JLabel("Grid Lines"), box); }
From source file:SelectionMonitor.java
public SelectionMonitor() { setLayout(new BorderLayout()); list = new JList(label); JScrollPane pane = new JScrollPane(list); // Format the list and the buttons in a vertical box Box rightBox = new Box(BoxLayout.Y_AXIS); Box leftBox = new Box(BoxLayout.Y_AXIS); // Monitor all list selections list.addListSelectionListener(new RadioUpdater()); for (int i = 0; i < label.length; i++) { checks[i] = new JCheckBox("Selection " + i); checks[i].setEnabled(false);//from w ww . j av a2 s. c o m rightBox.add(checks[i]); } leftBox.add(pane); add(rightBox, BorderLayout.EAST); add(leftBox, BorderLayout.WEST); }
From source file:com.googlecode.vfsjfilechooser2.accessories.bookmarks.BookmarksManagerPanel.java
public BookmarksManagerPanel(BookmarksDialog parentDialog, VFSJFileChooser chooser) { this.parentDialog = parentDialog; this.chooser = chooser; model = new Bookmarks(); table = new JTable(model); scrollPane = new JScrollPane(table); table.setPreferredScrollableViewportSize(tableSize); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); bCancel = new JButton(VFSResources.getMessage("VFSJFileChooser.closeButtonText")); bOpen = new JButton(VFSResources.getMessage("VFSJFileChooser.openButtonText")); bOpen.setIcon(new ImageIcon( getClass().getResource("/com/googlecode/vfsjfilechooser2/plaf/icons/document-open.png"))); bOpen.setHorizontalAlignment(SwingConstants.LEFT); bAdd = new JButton(VFSResources.getMessage("VFSJFileChooser.addButtonText")); bAdd.setIcon(/* ww w . j a va2 s. c o m*/ new ImageIcon(getClass().getResource("/com/googlecode/vfsjfilechooser2/plaf/icons/list-add.png"))); bAdd.setHorizontalAlignment(SwingConstants.LEFT); bEdit = new JButton(VFSResources.getMessage("VFSJFileChooser.editButtonText")); bEdit.setIcon( new ImageIcon(getClass().getResource("/com/googlecode/vfsjfilechooser2/plaf/icons/book_edit.png"))); bEdit.setHorizontalAlignment(SwingConstants.LEFT); bDelete = new JButton(VFSResources.getMessage("VFSJFileChooser.deleteButtonText")); bDelete.setIcon(new ImageIcon( getClass().getResource("/com/googlecode/vfsjfilechooser2/plaf/icons/list-remove.png"))); bDelete.setHorizontalAlignment(SwingConstants.LEFT); bMoveUp = new JButton(VFSResources.getMessage("VFSJFileChooser.moveUpButtonText")); bMoveUp.setIcon( new ImageIcon(getClass().getResource("/com/googlecode/vfsjfilechooser2/plaf/icons/go-up.png"))); bMoveUp.setHorizontalAlignment(SwingConstants.LEFT); bMoveDown = new JButton(VFSResources.getMessage("VFSJFileChooser.moveDownButtonText")); bMoveDown.setIcon( new ImageIcon(getClass().getResource("/com/googlecode/vfsjfilechooser2/plaf/icons/go-down.png"))); bMoveDown.setHorizontalAlignment(SwingConstants.LEFT); final ActionHandler ah = new ActionHandler(); bOpen.addActionListener(ah); bCancel.addActionListener(ah); bEdit.addActionListener(ah); bAdd.addActionListener(ah); bDelete.addActionListener(ah); bMoveUp.addActionListener(ah); bMoveDown.addActionListener(ah); final Box south = Box.createHorizontalBox(); south.add(Box.createHorizontalGlue()); south.add(bCancel); south.add(Box.createHorizontalGlue()); final JPanel buttons = new JPanel(new GridLayout(0, 1, 5, 5)); buttons.add(bAdd); buttons.add(bEdit); buttons.add(bDelete); buttons.add(bOpen); buttons.add(Box.createVerticalStrut(10)); buttons.add(bMoveUp); buttons.add(bMoveDown); JPanel east = new JPanel(); east.add(buttons, BorderLayout.NORTH); east.add(new JPanel(), BorderLayout.CENTER); // don't ask setLayout(new BorderLayout(10, 10)); add(scrollPane, BorderLayout.CENTER); add(south, BorderLayout.SOUTH); add(east, BorderLayout.EAST); setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, UIManager.getColor("Panel.background"))); }
From source file:org.stanwood.swing.AboutDialog.java
private JComponent createAuthorsTab() { JScrollPane scroll = new JScrollPane(); scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); Box box = Box.createVerticalBox(); box.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); for (Author author : authors) { box.add(new JLabel(author.getName())); JXHyperlink link = new JXHyperlink( new LinkAction(this, author.getEmail(), "mailto:" + author.getEmail())); box.add(link);//from w ww . j av a 2 s . c o m link.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0)); JLabel lblDescription = new JLabel(author.getDescription()); lblDescription.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0)); box.add(lblDescription); } scroll.getViewport().add(box); return scroll; }
From source file:FrameDemo2.java
protected JComponent createOptionControls() { JLabel label1 = new JLabel("Decoration options for subsequently created frames:"); ButtonGroup bg1 = new ButtonGroup(); JLabel label2 = new JLabel("Icon options:"); ButtonGroup bg2 = new ButtonGroup(); // Create the buttons JRadioButton rb1 = new JRadioButton(); rb1.setText("Look and feel decorated"); rb1.setActionCommand(LF_DECORATIONS); rb1.addActionListener(this); rb1.setSelected(true);//from www . j av a 2 s . c om bg1.add(rb1); // JRadioButton rb2 = new JRadioButton(); rb2.setText("Window system decorated"); rb2.setActionCommand(WS_DECORATIONS); rb2.addActionListener(this); bg1.add(rb2); // JRadioButton rb3 = new JRadioButton(); rb3.setText("No decorations"); rb3.setActionCommand(NO_DECORATIONS); rb3.addActionListener(this); bg1.add(rb3); // // JRadioButton rb4 = new JRadioButton(); rb4.setText("Default icon"); rb4.setActionCommand(DEFAULT_ICON); rb4.addActionListener(this); rb4.setSelected(true); bg2.add(rb4); // JRadioButton rb5 = new JRadioButton(); rb5.setText("Icon from a JPEG file"); rb5.setActionCommand(FILE_ICON); rb5.addActionListener(this); bg2.add(rb5); // JRadioButton rb6 = new JRadioButton(); rb6.setText("Painted icon"); rb6.setActionCommand(PAINT_ICON); rb6.addActionListener(this); bg2.add(rb6); // Add everything to a container. Box box = Box.createVerticalBox(); box.add(label1); box.add(Box.createVerticalStrut(5)); // spacer box.add(rb1); box.add(rb2); box.add(rb3); // box.add(Box.createVerticalStrut(15)); // spacer box.add(label2); box.add(Box.createVerticalStrut(5)); // spacer box.add(rb4); box.add(rb5); box.add(rb6); // Add some breathing room. box.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); return box; }
From source file:SoundPlayer.java
void addMidiControls() { // Add a slider to control the tempo final JSlider tempo = new JSlider(50, 200); tempo.setValue((int) (sequencer.getTempoFactor() * 100)); tempo.setBorder(new TitledBorder("Tempo Adjustment (%)")); java.util.Hashtable labels = new java.util.Hashtable(); labels.put(new Integer(50), new JLabel("50%")); labels.put(new Integer(100), new JLabel("100%")); labels.put(new Integer(200), new JLabel("200%")); tempo.setLabelTable(labels);//from ww w . j a va 2s .c om tempo.setPaintLabels(true); // The event listener actually changes the tmpo tempo.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { sequencer.setTempoFactor(tempo.getValue() / 100.0f); } }); this.add(tempo); // Create rows of solo and checkboxes for each track Track[] tracks = sequence.getTracks(); for (int i = 0; i < tracks.length; i++) { final int tracknum = i; // Two checkboxes per track final JCheckBox solo = new JCheckBox("solo"); final JCheckBox mute = new JCheckBox("mute"); // The listeners solo or mute the track solo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sequencer.setTrackSolo(tracknum, solo.isSelected()); } }); mute.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sequencer.setTrackMute(tracknum, mute.isSelected()); } }); // Build up a row Box box = Box.createHorizontalBox(); box.add(new JLabel("Track " + tracknum)); box.add(Box.createHorizontalStrut(10)); box.add(solo); box.add(Box.createHorizontalStrut(10)); box.add(mute); box.add(Box.createHorizontalGlue()); // And add it to this component this.add(box); } }
From source file:Main.java
public Main(int axis) { super(BoxLayout.Y_AXIS); container = new Box(axis); container.setAlignmentX(Box.LEFT_ALIGNMENT); add(container);//from ww w . j a v a 2 s . co m 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:de.interactive_instruments.ShapeChange.UI.DefaultDialog.java
private JPanel createTab2() { final JPanel reportPanel = new JPanel(new GridLayout(3, 1)); reportGroup = new ButtonGroup(); String param = options.parameter("reportLevel"); addRadioButton(reportPanel, reportGroup, "Error", "ERROR", param); addRadioButton(reportPanel, reportGroup, "Warning", "WARNING", param); addRadioButton(reportPanel, reportGroup, "Info", "INFO", param); reportPanel.setBorder(new TitledBorder(new LineBorder(Color.black), "Report options", TitledBorder.LEFT, TitledBorder.TOP));// w w w . j av a 2 s . co m final JPanel rulePanel = new JPanel(new GridLayout(3, 1)); ruleGroup = new ButtonGroup(); param = options.parameter(Options.TargetXmlSchemaClass, "defaultEncodingRule"); addRadioButton(rulePanel, ruleGroup, "GML 3.2", "iso19136_2007", param); addRadioButton(rulePanel, ruleGroup, "GML 3.3", "gml33", param); addRadioButton(rulePanel, ruleGroup, "ISO/TS 19139", "iso19139_2007", param); addRadioButton(rulePanel, ruleGroup, "GML 3.2 (ShapeChange extensions)", "iso19136_2007_ShapeChange_1.0_extensions", param); addRadioButton(rulePanel, ruleGroup, "GML 3.3 (INSPIRE extensions)", "iso19136_2007_INSPIRE_Extensions", param); rulePanel.setBorder(new TitledBorder(new LineBorder(Color.black), "Default encoding rule", TitledBorder.LEFT, TitledBorder.TOP)); final JPanel otherPanel = new JPanel(new GridLayout(2, 1)); docCB = new JCheckBox("Include documentation", true); boolean b = true; String s = options.parameter(Options.TargetXmlSchemaClass, "includeDocumentation"); if (s != null && s.equals("false")) b = false; docCB.setSelected(b); otherPanel.add(docCB); visCB = new JCheckBox("Ignore visibility"); b = true; s = options.parameter("publicOnly"); if (s != null && s.equals("false")) b = false; visCB.setSelected(!b); otherPanel.add(visCB); otherPanel.setBorder(new TitledBorder(new LineBorder(Color.black), "Other options", TitledBorder.LEFT, TitledBorder.TOP)); Box innerBox = Box.createHorizontalBox(); innerBox.add(reportPanel); innerBox.add(otherPanel); Box mainBox = Box.createVerticalBox(); mainBox.add(innerBox); mainBox.add(rulePanel); JPanel panel = new JPanel(new BorderLayout()); panel.add(mainBox, BorderLayout.CENTER); return panel; }
From source file:org.jannocessor.ui.RenderPreviewDialog.java
private JComponent createOutput(String title, String content) { editor = new JEditorPane(); JScrollPane scroll = new JScrollPane(editor, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setMinimumSize(new Dimension(100, 100)); editor.setContentType("text/java_output"); editor.setEditable(false);/*w w w .jav a 2 s. c o m*/ editor.setText(content); editor.addKeyListener(keyListener); JLabel header = new JLabel(title); Box box = Box.createVerticalBox(); box.add(header); box.add(scroll); return box; }
From source file:pcgen.gui2.dialog.CharacterHPDialog.java
private void initComponents() { setDefaultCloseOperation(DISPOSE_ON_CLOSE); Container pane = getContentPane(); pane.setLayout(new BorderLayout()); JTable table = new JTable(tableModel) { @Override//w w w . ja v a 2s . com public TableCellEditor getCellEditor(int row, int column) { if (column == 5) {//TODO: the max roll should be calculated in a different manner String hd = levels.getClassTaken(levels.getElementAt(row)).getHD(); int max = NumberUtils.toInt(hd); return new IntegerEditor(1, max); } else { return super.getCellEditor(row, column); } } }; table.setDefaultRenderer(JButton.class, new Renderer()); table.setDefaultEditor(JButton.class, new Editor()); table.setCellSelectionEnabled(false); table.setRowHeight(new IntegerEditor(1, 10).getPreferredSize().height); JTableHeader header = table.getTableHeader(); header.setReorderingAllowed(false); JScrollPane scrollPane = new JScrollPane(table); pane.add(scrollPane, BorderLayout.CENTER); Box box = Box.createHorizontalBox(); box.add(new JLabel("Total Hp:")); box.add(Box.createHorizontalStrut(3)); final ReferenceListener<Integer> hpListener = new ReferenceListener<Integer>() { @Override public void referenceChanged(ReferenceEvent<Integer> e) { totalHp.setText(e.getNewReference().toString()); } }; ReferenceFacade<Integer> hpRef = character.getTotalHPRef(); totalHp.setText(hpRef.get().toString()); hpRef.addReferenceListener(hpListener); box.add(totalHp); box.add(Box.createHorizontalStrut(5)); JButton button = new JButton("Reroll All"); button.setActionCommand("Reroll"); button.addActionListener(this); box.add(button); box.add(Box.createHorizontalGlue()); button = new JButton("Close"); button.setActionCommand("Close"); button.addActionListener(this); box.add(button); pane.add(box, BorderLayout.SOUTH); addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { //Make sure to remove the listeners so that the garbage collector can //dispose of this dialog and prevent a memory leak levels.removeHitPointListener(tableModel); character.getTotalHPRef().removeReferenceListener(hpListener); } }); Utility.installEscapeCloseOperation(this); }