List of usage examples for javax.swing Box createRigidArea
public static Component createRigidArea(Dimension d)
From source file:LayeredPaneDemo.java
public LayeredPaneDemo() { setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); // Create and load the duke icon. final ImageIcon icon = new ImageIcon("yourFile.gif"); // Create and set up the layered pane. layeredPane = new JLayeredPane(); layeredPane.setPreferredSize(new Dimension(300, 310)); layeredPane.setBorder(BorderFactory.createTitledBorder("Move the Mouse to Move Duke")); layeredPane.addMouseMotionListener(this); // This is the origin of the first label added. Point origin = new Point(10, 20); // This is the offset for computing the origin for the next label. int offset = 35; // Add several overlapping, colored labels to the layered pane // using absolute positioning/sizing. for (int i = 0; i < layerStrings.length; i++) { JLabel label = createColoredLabel(layerStrings[i], layerColors[i], origin); layeredPane.add(label, new Integer(i)); origin.x += offset;/* www.j a v a 2 s . c o m*/ origin.y += offset; } // Create and add the Duke label to the layered pane. dukeLabel = new JLabel(icon); if (icon != null) { dukeLabel.setBounds(15, 225, icon.getIconWidth(), icon.getIconHeight()); } else { System.err.println("Duke icon not found; using black square instead."); dukeLabel.setBounds(15, 225, 30, 30); dukeLabel.setOpaque(true); dukeLabel.setBackground(Color.BLACK); } layeredPane.add(dukeLabel, new Integer(2), 0); // Add control pane and layered pane to this JPanel. add(Box.createRigidArea(new Dimension(0, 10))); add(createControlPanel()); add(Box.createRigidArea(new Dimension(0, 10))); add(layeredPane); }
From source file:InternalFrameEventDemo.java
protected void createDisplayWindow() { JButton b1 = new JButton("Show internal frame"); b1.setActionCommand(SHOW);//w w w . j a va 2 s . c o m b1.addActionListener(this); JButton b2 = new JButton("Clear event info"); b2.setActionCommand(CLEAR); b2.addActionListener(this); display = new JTextArea(3, 30); display.setEditable(false); JScrollPane textScroller = new JScrollPane(display); // Have to supply a preferred size, or else the scroll // area will try to stay as large as the text area. textScroller.setPreferredSize(new Dimension(200, 75)); textScroller.setMinimumSize(new Dimension(10, 10)); displayWindow = new JInternalFrame("Event Watcher", true, // resizable false, // not closable false, // not maximizable true); // iconifiable JPanel contentPane = new JPanel(); contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); b1.setAlignmentX(CENTER_ALIGNMENT); contentPane.add(b1); contentPane.add(Box.createRigidArea(new Dimension(0, 5))); contentPane.add(textScroller); contentPane.add(Box.createRigidArea(new Dimension(0, 5))); b2.setAlignmentX(CENTER_ALIGNMENT); contentPane.add(b2); displayWindow.setContentPane(contentPane); displayWindow.pack(); displayWindow.setVisible(true); }
From source file:ro.nextreports.designer.wizpublish.SelectEntityWizardPanel.java
private void jbInit() { this.setLayout(new GridBagLayout()); banner.setTitle(I18NSupport.getString("wizard.publish.entities.select")); btnAdd.setIcon(ImageUtil.getImageIcon("add")); btnAdd.setPreferredSize(btnDim);//from ww w . j a va 2 s .com btnAdd.setMinimumSize(btnDim); btnAdd.setMaximumSize(btnDim); btnAdd.setToolTipText(I18NSupport.getString("listselectionpanel.add")); btnAdd.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { add(); } }); btnRem.setIcon(ImageUtil.getImageIcon("delete")); btnRem.setPreferredSize(btnDim); btnRem.setMinimumSize(btnDim); btnRem.setMaximumSize(btnDim); btnRem.setToolTipText(I18NSupport.getString("listselectionpanel.remove")); btnRem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { remove(); } }); list.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { remove(); } } }); scrList.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrList.setMinimumSize(scrDim); scrList.setPreferredSize(scrDim); scrList.getViewport().add(list, null); list.setModel(listModel); JPanel btnPanel = new JPanel(); btnPanel.setLayout(new BoxLayout(btnPanel, BoxLayout.Y_AXIS)); btnPanel.add(Box.createGlue()); btnPanel.add(btnAdd); btnPanel.add(Box.createRigidArea(new Dimension(5, 5))); btnPanel.add(btnRem); btnPanel.add(Box.createGlue()); add(scrList, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHEAST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); add(btnPanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); }
From source file:pipeline.parameter_cell_views.IntRangeSlider.java
public IntRangeSlider() { super();//w w w . j a v a2 s. co m addMouseWheelListener(e -> { int rotation = e.getWheelRotation(); int change = (int) ((currentValue1 - currentValue0 + 1) * rotation * Utils.getMouseWheelClickFactor()); int newCurrentValue0 = currentValue0; int newCurrentValue1 = currentValue1; int saveIntMinimum = minimum; int saveIntMaximum = maximum; newCurrentValue0 += change; newCurrentValue1 += change; if (!((e.getModifiers() & java.awt.event.InputEvent.ALT_MASK) > 0)) { if (newCurrentValue1 > saveIntMaximum) { int difference = newCurrentValue1 - newCurrentValue0; newCurrentValue1 = saveIntMaximum; newCurrentValue0 = newCurrentValue1 - difference; if (newCurrentValue0 < 0) Utils.log("<0", LogLevel.WARNING); } if (newCurrentValue0 < saveIntMinimum) { int difference = newCurrentValue1 - newCurrentValue0; newCurrentValue0 = saveIntMinimum; newCurrentValue1 = newCurrentValue0 + difference; if (newCurrentValue0 < 0) Utils.log("<0", LogLevel.WARNING); } } else { } currentParameter .setValue(new int[] { newCurrentValue0, newCurrentValue1, saveIntMinimum, saveIntMaximum }); updateValues(); currentParameter.fireValueChanged(false, false, true); }); nf.setGroupingUsed(true); nf.setMaximumFractionDigits(3); nf.setMaximumIntegerDigits(12); setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; parameterName = new JLabel(""); c.gridx = 0; c.gridy = 0; c.weighty = 1.0; c.weightx = 0.0; c.gridwidth = 4; add(Box.createRigidArea(new Dimension(0, 5)), c); slider = new RangeSlider(0, 20); slider.addChangeListener(new sliderListener()); c.gridx = 0; c.gridy = 1; c.weighty = 1.0; c.weightx = 0.0; c.gridwidth = 4; add(slider, c); c.gridwidth = 1; c.gridx = 0; c.gridy = 2; c.weighty = 1.0; c.weightx = 1.0; c.gridwidth = 4; Component comp = Box.createRigidArea(new Dimension(0, 10)); ((JComponent) comp).setOpaque(true); add(comp, c); c.gridwidth = 1; currentTextValue0 = new JTextField("" + slider.getValue()); currentTextValue1 = new JTextField("" + slider.getUpperValue()); currentTextValue0.addActionListener(new textBoxListenerTriggersUpdate()); currentTextValue1.addActionListener(new textBoxListenerTriggersUpdate()); Font smallerFont = new Font(currentTextValue0.getFont().getName(), currentTextValue0.getFont().getStyle(), currentTextValue0.getFont().getSize() - 2); textMinimum = new JTextField("0"); textMinimum.setFont(smallerFont); textMinimum.addActionListener(new minimumListener()); textMaximum = new JTextField("50"); textMaximum.setFont(smallerFont); textMaximum.addActionListener(new maximumListener()); textMaximum.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { if (!silenceUpdate) { slider.setMinimum(parseTextBox(textMinimum).intValue()); minimum = slider.getMinimum(); slider.setMaximum(parseTextBox(textMaximum).intValue()); maximum = slider.getMaximum(); slider.setValue(parseTextBox(currentTextValue0).intValue()); slider.setUpperValue(parseTextBox(currentTextValue1).intValue()); currentValue0 = slider.getValue(); currentValue1 = slider.getUpperValue(); currentParameter.setValue(new int[] { currentValue0, currentValue1, minimum, maximum }); } } }); textValueFrame = new JPanel(); textValueFrame.setBackground(getBackground()); textValueFrame.setLayout(new GridBagLayout()); c.gridx = 0; c.gridy = 0; c.weighty = 1.0; c.weightx = 0.1; textValueFrame.add(textMinimum, c); c.gridx = 1; c.gridy = 0; c.weighty = 1.0; c.weightx = 0.3; textValueFrame.add(currentTextValue0, c); c.gridx = 2; c.gridy = 0; c.weighty = 1.0; c.weightx = 0.3; textValueFrame.add(currentTextValue1, c); c.gridx = 3; c.gridy = 0; c.weighty = 1.0; c.weightx = 0.1; textValueFrame.add(textMaximum, c); c.gridx = 0; c.gridy = 3; c.weighty = 1.0; c.weightx = 0.3; c.gridwidth = 4; add(textValueFrame, c); c.gridwidth = 1; parameterName = new JLabel("parameter"); c.gridx = 0; c.gridy = 4; c.weighty = 1.0; c.weightx = 0.01; c.gridwidth = 1; add(parameterName, c); resetMin = new JButton("Min"); resetMin.setActionCommand("Reset Min"); resetMin.addActionListener(new buttonListener()); resetMax = new JButton("Max"); resetMax.setActionCommand("Reset Max"); resetMax.addActionListener(new buttonListener()); resetRange = new JButton("MinMax"); resetRange.setActionCommand("Reset Range"); resetRange.addActionListener(new buttonListener()); c.gridx = 1; c.gridy = 4; c.weighty = 1.0; c.weightx = 0.2; c.gridwidth = 1; add(resetMin, c); c.gridx = 2; c.gridy = 4; c.weighty = 1.0; c.weightx = 0.2; c.gridwidth = 1; add(resetMax, c); c.gridx = 3; c.gridy = 4; c.weighty = 1.0; c.weightx = 0.2; c.gridwidth = 1; add(resetRange, c); }
From source file:com.opendoorlogistics.studio.components.geocoder.SearchResultsPanel.java
SearchResultsPanel(final NominatimConfig config, final GeocodeModel model) { this.model = model; this.config = config; // server selector at top serverBox = Controls.createServerBox(config.getServer()); serverBox.addValueChangedListener(new ValueChangedListener<String>() { @Override//from w ww . ja v a 2s. c om public void comboValueChanged(String newValue) { updateAppearance(); } }); countryCode = Controls.createCountryBox(config.getCountryCode()); countryCode.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { updateAppearance(); } }); // refresh button by server selector refresh = new JButton(Icons.loadFromStandardPath("view-refresh-6.png")); refresh.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { refreshResults(); } }); refresh.setToolTipText("Re-run the query"); // add the controls addLine(Controls.createServerLabel(), serverBox); addWhitespace(6); addLine(Controls.createCountryFilterLabel(), countryCode, Box.createRigidArea(new Dimension(10, 1)), refresh); addWhitespace(); // results table in the middle table = new JTable(); table.setColumnSelectionAllowed(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { readSelectedIntoModel(); } }); table.setFillsViewportHeight(true); JScrollPane scrollPane = new JScrollPane(table); add(scrollPane); setTableModel(); model.addListener(this); updateAppearance(); }
From source file:CutAndPasteDemo.java
public CutAndPasteDemo() { super("Cut And Paste Demonstration"); clipboard = getToolkit().getSystemClipboard(); GraphicsEnvironment.getLocalGraphicsEnvironment(); Font font = new Font("LucidaSans", Font.PLAIN, 15); textArea1 = new JTextArea(davidMessage + andyMessage, 5, 25); textArea2 = new JTextArea("<Paste text here>", 5, 25); textArea1.setFont(font);//from w w w. j a v a 2s. co m textArea2.setFont(font); JPanel jPanel = new JPanel(); JMenuBar jMenuBar = new JMenuBar(); JMenuItem cutItem = new JMenuItem("Cut"); JMenuItem pasteItem = new JMenuItem("Paste"); JMenu jMenu = new JMenu("Edit"); jMenu.add(cutItem); jMenu.add(pasteItem); cutItem.addActionListener(new CutActionListener()); pasteItem.addActionListener(new PasteActionListener()); jMenuBar.add(jMenu); jPanel.add(jMenuBar); jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS)); jPanel.add(textArea1); jPanel.add(Box.createRigidArea(new Dimension(0, 10))); jPanel.add(textArea2); getContentPane().add(jPanel, BorderLayout.CENTER); }
From source file:InternalFrameEventDemo.java
protected void createDisplayWindow() { JButton b1 = new JButton("Show internal frame"); b1.setActionCommand(SHOW);/*from w ww. java2 s. c o m*/ b1.addActionListener(this); JButton b2 = new JButton("Clear event info"); b2.setActionCommand(CLEAR); b2.addActionListener(this); display = new JTextArea(3, 30); display.setEditable(false); JScrollPane textScroller = new JScrollPane(display); //Have to supply a preferred size, or else the scroll //area will try to stay as large as the text area. textScroller.setPreferredSize(new Dimension(200, 75)); textScroller.setMinimumSize(new Dimension(10, 10)); displayWindow = new JInternalFrame("Event Watcher", true, //resizable false, //not closable false, //not maximizable true); //iconifiable JPanel contentPane = new JPanel(); contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); b1.setAlignmentX(CENTER_ALIGNMENT); contentPane.add(b1); contentPane.add(Box.createRigidArea(new Dimension(0, 5))); contentPane.add(textScroller); contentPane.add(Box.createRigidArea(new Dimension(0, 5))); b2.setAlignmentX(CENTER_ALIGNMENT); contentPane.add(b2); displayWindow.setContentPane(contentPane); displayWindow.pack(); displayWindow.setVisible(true); }
From source file:be.nbb.demetra.dfm.DfmExecViewTopComponent.java
@Override public JComponent getToolbarRepresentation() { JToolBar toolBar = NbComponents.newInnerToolbar(); toolBar.addSeparator();// ww w .ja va 2s .com toolBar.add(Box.createRigidArea(new Dimension(5, 0))); JToggleButton startStop = (JToggleButton) toolBar .add(new JToggleButton(StartStopCommand.INSTANCE.toAction(this))); startStop.setIcon(DemetraUiIcon.COMPILE_16); startStop.setDisabledIcon(createDisabledIcon(startStop.getIcon())); startStop.setToolTipText("Start/Stop"); JButton edit = toolBar.add(EditSpecCommand.INSTANCE.toAction(this)); edit.setIcon(DemetraUiIcon.PREFERENCES); edit.setDisabledIcon(createDisabledIcon(edit.getIcon())); edit.setToolTipText("Specification"); JButton clear = toolBar.add(ClearCommand.INSTANCE.toAction(this)); clear.setIcon(DemetraUiIcon.EDIT_CLEAR_16); clear.setDisabledIcon(createDisabledIcon(clear.getIcon())); clear.setToolTipText("Clear"); SwingColorSchemeSupport colorSchemeSupport = SwingColorSchemeSupport .from(DemetraUI.getInstance().getColorScheme()); sparkline = (ChartPanel) toolBar .add(Charts.avoidScaling(new ChartPanel(Charts.createSparkLineChart(null)))); sparkline.setPreferredSize(new Dimension(150, 16)); sparkline.setMaximumSize(new Dimension(150, 16)); sparkline.getChart().getXYPlot().setDataset(dataset); sparkline.getChart().getXYPlot().getRenderer() .setBasePaint(colorSchemeSupport.getLineColor(ColorScheme.KnownColor.GREEN)); sparkline.setBackground(colorSchemeSupport.getPlotColor()); sparkline.setBorder(BorderFactory.createLineBorder(colorSchemeSupport.getGridColor())); sparkline.setToolTipText("loglikelihood"); return toolBar; }
From source file:pcgen.gui2.tabs.bio.BiographyInfoPane.java
private void initComponents() { setLayout(new GridBagLayout()); Box vbox = Box.createVerticalBox(); allButton.setText(LanguageBundle.getString("in_all")); //$NON-NLS-1$ allButton.setActionCommand(ALL_COMMAND); noneButton.setText(LanguageBundle.getString("in_none")); //$NON-NLS-1$ noneButton.setActionCommand(NONE_COMMAND); Box hbox = Box.createHorizontalBox(); hbox.add(new JLabel(LanguageBundle.getString("in_descCheckItem"))); //$NON-NLS-1$ hbox.add(Box.createRigidArea(new Dimension(5, 0))); hbox.add(allButton);/*from w w w .j a v a 2 s . co m*/ hbox.add(Box.createRigidArea(new Dimension(3, 0))); hbox.add(noneButton); vbox.add(hbox); itemsPanel.setLayout(new GridBagLayout()); itemsPanel.setBorder(new EmptyBorder(8, 5, 8, 5)); vbox.add(Box.createVerticalStrut(10)); detailsScroll = new JScrollPane(itemsPanel); detailsScroll.setPreferredSize(detailsScroll.getMaximumSize()); detailsScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); detailsScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); detailsScroll.setMinimumSize(new Dimension(600, 0)); vbox.add(detailsScroll); vbox.add(Box.createVerticalStrut(10)); hbox = Box.createHorizontalBox(); hbox.add(Box.createHorizontalGlue()); addCustomItemButton = new JButton(); hbox.add(addCustomItemButton); hbox.add(Box.createHorizontalGlue()); vbox.add(hbox); vbox.add(Box.createVerticalGlue()); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.NORTHWEST; gbc.weightx = 1; gbc.fill = GridBagConstraints.VERTICAL; gbc.weighty = 1; gbc.insets = new Insets(5, 5, 5, 5); add(vbox, gbc); }
From source file:Converter.java
/** * Create the ConversionPanels (one for metric, another for U.S.). I used * "U.S." because although Imperial and U.S. distance measurements are the * same, this program could be extended to include volume measurements, which * aren't the same./*from ww w . j a va2 s .co m*/ */ public Converter() { // Create Unit objects for metric distances, and then // instantiate a ConversionPanel with these Units. metricDistances[0] = new Unit("Centimeters", 0.01); metricDistances[1] = new Unit("Meters", 1.0); metricDistances[2] = new Unit("Kilometers", 1000.0); metricPanel = new ConversionPanel(this, "Metric System", metricDistances, dataModel); // Create Unit objects for U.S. distances, and then // instantiate a ConversionPanel with these Units. usaDistances[0] = new Unit("Inches", 0.0254); usaDistances[1] = new Unit("Feet", 0.305); usaDistances[2] = new Unit("Yards", 0.914); usaDistances[3] = new Unit("Miles", 1613.0); usaPanel = new ConversionPanel(this, "U.S. System", usaDistances, new FollowerRangeModel(dataModel)); // Create a JPanel, and add the ConversionPanels to it. mainPane = new JPanel(); mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.PAGE_AXIS)); if (MULTICOLORED) { mainPane.setOpaque(true); mainPane.setBackground(new Color(255, 0, 0)); } mainPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); mainPane.add(Box.createRigidArea(new Dimension(0, 5))); mainPane.add(metricPanel); mainPane.add(Box.createRigidArea(new Dimension(0, 5))); mainPane.add(usaPanel); mainPane.add(Box.createGlue()); resetMaxValues(true); }