List of usage examples for javax.swing Box createRigidArea
public static Component createRigidArea(Dimension d)
From source file:org.openmicroscopy.shoola.agents.treeviewer.util.SaveResultsDialog.java
/** * Builds and lays out the controls// w w w . j a v a 2s .c om * * @return See above. */ private JPanel buildToolBar() { JPanel bar = new JPanel(); bar.add(saveButton); bar.add(Box.createRigidArea(UIUtilities.H_SPACER_SIZE)); bar.add(cancelButton); bar.add(Box.createRigidArea(UIUtilities.H_SPACER_SIZE)); return UIUtilities.buildComponentPanelRight(bar); }
From source file:edu.ucla.stat.SOCR.motionchart.MotionMouseListener.java
protected JPanel getPanel(final JDialog dialog, DefaultTableModel tModel, ArrayList<String> rowIdentifiers) { JPanel panel = new JPanel(); JButton close = new JButton("Close"); close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.setVisible(false);/* www .j a v a2s .co m*/ } }); close.setAlignmentX(Component.CENTER_ALIGNMENT); RowHeaderTable table = new RowHeaderTable(tModel); table.getDataTable().setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.getDataTable().setDefaultRenderer(Object.class, new ColorRenderer(false)); table.setCellsEditable(false); table.setHeadersEditable(false); for (int r = 0; r < tModel.getRowCount() && rowIdentifiers.size() <= tModel.getRowCount(); r++) { table.getRowHeaderModel().setValueAt(rowIdentifiers.get(r), r, 0); } Dimension d = table.getRowHeaderTable().getPreferredScrollableViewportSize(); d.width = 55; table.getRowHeaderTable().setPreferredScrollableViewportSize(d); panel.setLayout(new BoxLayout(panel, BoxLayout.PAGE_AXIS)); panel.add(table); panel.add(Box.createRigidArea(new Dimension(0, 5))); panel.add(close); return panel; }
From source file:lab4.YouQuiz.java
private void switchToQuizMode() { JToolBar toolbar = new JToolBar(); toolbar.setFloatable(false);/*from w ww .j av a2 s. c o m*/ backButton.setFocusable(false); toolbar.add(backButton); toolbar.setAlignmentX(0); backButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { contentPanel.setQuestion(questionsArray.get(--questionIndex)); forwardButton.setEnabled(true); if (questionIndex - 1 < 0) { backButton.setEnabled(false); } updateAnswerForm(); } }); forwardButton.setFocusable(false); toolbar.add(forwardButton); toolbar.setAlignmentX(0); forwardButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { contentPanel.setQuestion(questionsArray.get(++questionIndex)); backButton.setEnabled(true); if (questionsArray.size() == questionIndex + 1) { forwardButton.setEnabled(false); } updateAnswerForm(); } }); speakButton.setFocusable(false); toolbar.add(speakButton); toolbar.setAlignmentX(0); speakButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { Audio audio = Audio.getInstance(); InputStream sound = null; try { sound = audio.getAudio(questionsArray.get(questionIndex).getQuestion(), Language.ENGLISH); } catch (IOException ex) { Logger.getLogger(YouQuiz.class.getName()).log(Level.SEVERE, null, ex); } try { audio.play(sound); } catch (JavaLayerException ex) { Logger.getLogger(YouQuiz.class.getName()).log(Level.SEVERE, null, ex); } } }); refreshButton.setFocusable(false); toolbar.add(refreshButton); toolbar.setAlignmentX(0); refreshButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { shuffleQuestions(); questionIndex = 0; backButton.setEnabled(false); if (questionsArray.size() == 1) { forwardButton.setEnabled(false); } else { forwardButton.setEnabled(true); } contentPanel.setQuestion(questionsArray.get(questionIndex)); updateAnswerForm(); } }); micButton.setFocusable(false); toolbar.add(micButton); toolbar.setAlignmentX(0); micButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { GSpeechDuplex dup = new GSpeechDuplex(); dup.addResponseListener(new GSpeechResponseListener() { @Override public void onResponse(GoogleResponse gr) { if (questionsArray.get(questionIndex).checkAnswer(gr.getResponse())) { JOptionPane.showMessageDialog(null, "Thats Great, Correct Answer", "Excellent", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "Oops! '" + gr.getResponse() + "' is a wrong Answer. Its '" + questionsArray.get(questionIndex).getAnswer().get(0) + "'", "Sorry", JOptionPane.ERROR_MESSAGE); } } }); Microphone mic = new Microphone(FLACFileWriter.FLAC); File file = new File("CRAudioTest.flac"); try { mic.captureAudioToFile(file); Thread.sleep(5000); mic.close(); byte[] data = Files.readAllBytes(mic.getAudioFile().toPath()); dup.recognize(data, (int) mic.getAudioFormat().getSampleRate()); mic.getAudioFile().delete(); } catch (LineUnavailableException | InterruptedException | IOException ex) { } } }); contentPanel = new ContentPanel(); contentPanel.add(Box.createRigidArea(new Dimension(0, 10))); contentPanel.add(toolbar, BorderLayout.NORTH); contentPanel.add(Box.createRigidArea(new Dimension(0, 50))); contentPanel.add(contentPanel.questionLabel); add(contentPanel, BorderLayout.CENTER); if (questionsArray.isEmpty()) { refreshButton.setEnabled(false); backButton.setEnabled(false); forwardButton.setEnabled(false); speakButton.setEnabled(false); } else { questionIndex = 0; backButton.setEnabled(false); if (questionsArray.size() == 1) { forwardButton.setEnabled(false); } contentPanel.setQuestion(questionsArray.get(questionIndex)); contentPanel.add(Box.createRigidArea(new Dimension(0, 20))); contentPanel.add(contentPanel.answerPanel); contentPanel.add(Box.createRigidArea(new Dimension(0, 10))); contentPanel.add(contentPanel.checkButton); updateAnswerForm(); } }
From source file:org.obiba.onyx.jade.instrument.ricelake.RiceLakeWeightInstrumentRunner.java
protected JPanel buildResultsSubPanel() { final JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.add(new JLabel(resourceBundle.getString("Weight") + ":")); panel.add(Box.createRigidArea(new Dimension(10, 0))); panel.add(weightTxt);// w w w. j a v a 2 s.c om panel.add(Box.createRigidArea(new Dimension(10, 0))); panel.add(new JLabel(resourceBundle.getString("kg"))); panel.setAlignmentX(Component.LEFT_ALIGNMENT); return panel; }
From source file:org.openmicroscopy.shoola.agents.treeviewer.util.SaveResultsDialog.java
/** * Builds and lays out the elements indicating what to save. * * @return See above./* w w w . j a v a2 s . co m*/ */ private JPanel buildContents() { JPanel buttons = new JPanel(); buttons.add(UIUtilities.setTextFont("Save results for")); buttons.setLayout(new BoxLayout(buttons, BoxLayout.Y_AXIS)); ButtonGroup group = new ButtonGroup(); JRadioButton b = new JRadioButton("Image from current window"); b.setSelected(activeWindow); buttons.add(b); group.add(b); b.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { activeWindow = (e.getStateChange() == ItemEvent.SELECTED); } }); b = new JRadioButton("Images from all image windows"); b.setSelected(activeWindow); buttons.add(b); group.add(b); buttons.add(Box.createRigidArea(UIUtilities.H_SPACER_SIZE)); buttons.add(UIUtilities.setTextFont("Save")); buttons.add(roi); buttons.add(table); JPanel row = new JPanel(); row.setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel l = new JLabel(); l.setText("Measurements File Name: "); row.add(l); row.add(nameField); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); p.add(UIUtilities.buildComponentPanel(buttons)); p.add(row); return p; }
From source file:io.github.jeremgamer.editor.panels.GeneralSettings.java
public GeneralSettings() { this.setBorder(BorderFactory.createTitledBorder("")); JPanel namePanel = new JPanel(); JLabel nameLabel = new JLabel("Nom :"); namePanel.add(nameLabel);// w w w . jav a 2 s.c o m name.setPreferredSize(new Dimension(220, 30)); namePanel.add(name); CaretListener caretUpdateName = new CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent e) { JTextField text = (JTextField) e.getSource(); gs.set("name", text.getText()); } }; name.addCaretListener(caretUpdateName); this.add(namePanel); adress.setEditable(false); CaretListener caretUpdateAdress = new CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent e) { JTextField text = (JTextField) e.getSource(); gs.set("adress", text.getText()); } }; adress.addCaretListener(caretUpdateAdress); JPanel subTypePanel = new JPanel(); JLabel typeLabel = new JLabel("Type :"); subTypePanel.add(typeLabel); type.setPreferredSize(new Dimension(220, 30)); type.addItem("Minecraft classique"); type.addItem("Minecraft personnalis"); if (new File("projects/" + Editor.getProjectName() + "/data.zip").exists()) { type.setSelectedIndex(1); browse.setEnabled(true); browse.setText("Supprimer l'import"); } else { browse.setEnabled(false); } type.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); if (combo.getSelectedIndex() == 1) { browse.setEnabled(true); adress.setEnabled(true); adress.setEditable(true); } else { browse.setEnabled(false); adress.setEnabled(false); adress.setEditable(false); } gs.set("type", combo.getSelectedIndex()); } }); subTypePanel.add(type); JPanel typePanel = new JPanel(); typePanel.setLayout(new BoxLayout(typePanel, BoxLayout.PAGE_AXIS)); typePanel.add(subTypePanel); JPanel browsePanel = new JPanel(); browsePanel.add(browse); JPanel adressPanel = new JPanel(); adressPanel.setLayout(new BoxLayout(adressPanel, BoxLayout.PAGE_AXIS)); JLabel adressLabel = new JLabel("Adresse de tlchargement :"); adressPanel.setPreferredSize(new Dimension(0, 47)); adress.setPreferredSize(new Dimension(0, 30)); adressPanel.add(adressLabel); adressPanel.add(adress); typePanel.add(adressPanel); this.add(typePanel); closeOnStart.setSelected(true); closeOnStart.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (closeOnStart.isSelected()) { gs.set("close", true); } else { gs.set("close", false); } } }); this.add(closeOnStart); JPanel look = new JPanel(); look.setBorder(BorderFactory.createTitledBorder("Apparence")); look.setPreferredSize(new Dimension(290, 340)); JPanel colors = new JPanel(); cDark.setSelected(true); bg.add(cLight); bg.add(cDark); colors.add(cLight); colors.add(cDark); cLight.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { gs.set("color", 0); } }); cDark.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { gs.set("color", 1); } }); look.add(colors); JPanel checks = new JPanel(); checks.setLayout(new BoxLayout(checks, BoxLayout.PAGE_AXIS)); borders.setSelected(true); borders.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (borders.isSelected()) { gs.set("borders", true); } else { gs.set("borders", false); } } }); resize.setSelected(true); resize.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (resize.isSelected()) { gs.set("resizable", true); } else { gs.set("resizable", false); } } }); alwaysOnTop.setSelected(false); alwaysOnTop.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (alwaysOnTop.isSelected()) { gs.set("top", true); } else { gs.set("top", false); } } }); checks.add(borders); checks.add(resize); checks.add(alwaysOnTop); checks.setPreferredSize(new Dimension(270, 60)); JPanel size = new JPanel(); width.setPreferredSize(new Dimension(57, 30)); widthMin.setPreferredSize(new Dimension(57, 30)); widthMax.setPreferredSize(new Dimension(57, 30)); height.setPreferredSize(new Dimension(57, 30)); heightMin.setPreferredSize(new Dimension(57, 30)); heightMax.setPreferredSize(new Dimension(57, 30)); JPanel widthPanel = new JPanel(); widthPanel.setPreferredSize(new Dimension(130, 150)); widthPanel.setBorder(BorderFactory.createTitledBorder("Largeur")); widthPanel.setLayout(new BoxLayout(widthPanel, BoxLayout.PAGE_AXIS)); JPanel widthPanelBase = new JPanel(); widthPanelBase.add(new JLabel("Base :")); widthPanelBase.add(width); JPanel widthPanelMin = new JPanel(); widthPanelMin.add(new JLabel("Min :")); widthPanelMin.add(Box.createRigidArea(new Dimension(5, 1))); widthPanelMin.add(widthMin); JPanel widthPanelMax = new JPanel(); widthPanelMax.add(new JLabel("Max :")); widthPanelMax.add(Box.createRigidArea(new Dimension(3, 1))); widthPanelMax.add(widthMax); widthPanel.add(widthPanelBase); widthPanel.add(widthPanelMin); widthPanel.add(widthPanelMax); JPanel heightPanel = new JPanel(); heightPanel.setPreferredSize(new Dimension(130, 150)); heightPanel.setBorder(BorderFactory.createTitledBorder("Hauteur")); heightPanel.setLayout(new BoxLayout(heightPanel, BoxLayout.PAGE_AXIS)); JPanel heightPanelBase = new JPanel(); heightPanelBase.add(new JLabel("Base :")); heightPanelBase.add(height); JPanel heightPanelMin = new JPanel(); heightPanelMin.add(new JLabel("Min :")); heightPanelMin.add(Box.createRigidArea(new Dimension(5, 1))); heightPanelMin.add(heightMin); JPanel heightPanelMax = new JPanel(); heightPanelMax.add(new JLabel("Max :")); heightPanelMax.add(Box.createRigidArea(new Dimension(3, 1))); heightPanelMax.add(heightMax); heightPanel.add(heightPanelBase); heightPanel.add(heightPanelMin); heightPanel.add(heightPanelMax); size.add(widthPanel); size.add(heightPanel); width.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); gs.set("width", spinner.getValue()); } }); widthMin.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); gs.set("widthMin", spinner.getValue()); } }); widthMax.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); ; gs.set("widthMax", spinner.getValue()); } }); height.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); gs.set("height", spinner.getValue()); } }); heightMin.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); gs.set("heightMin", spinner.getValue()); } }); heightMax.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); ; gs.set("heightMax", spinner.getValue()); } }); look.add(checks); look.add(size); JPanel bottom = new JPanel(); bottom.setLayout(new BoxLayout(bottom, BoxLayout.LINE_AXIS)); JButton music = new JButton("Ajouter de la musique"); music.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { new MusicFrame((JFrame) SwingUtilities.windowForComponent(adress), gs); } }); bottom.add(music); JButton icons = new JButton("Icnes"); icons.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { new IconFrame((JFrame) SwingUtilities.windowForComponent(adress)); } }); bottom.add(icons); look.add(bottom); this.add(look); load(); }
From source file:org.apache.jmeter.protocol.http.control.gui.WebServiceSamplerGui.java
private final JPanel createTopPanel() { JPanel topPanel = new JPanel(); topPanel.setLayout(new VerticalLayout(5, VerticalLayout.BOTH)); JPanel wsdlHelper = new JPanel(); wsdlHelper.setLayout(new BoxLayout(wsdlHelper, BoxLayout.Y_AXIS)); wsdlHelper.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), JMeterUtils.getResString("webservice_configuration_wizard"))); // $NON-NLS-1$ // Button for browsing webservice wsdl JPanel wsdlEntry = new JPanel(); wsdlEntry.setLayout(new BoxLayout(wsdlEntry, BoxLayout.X_AXIS)); Border margin = new EmptyBorder(0, 5, 0, 5); wsdlEntry.setBorder(margin);//from w w w . j a va2 s . c om wsdlHelper.add(wsdlEntry); wsdlEntry.add(wsdlField); wsdlEntry.add(wsdlButton); wsdlButton.addActionListener(this); // Web Methods JPanel listPanel = new JPanel(); listPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel selectLabel = new JLabel(JMeterUtils.getResString("webservice_methods")); // $NON-NLS-1$ wsdlMethods = new JLabeledChoice(); wsdlHelper.add(listPanel); listPanel.add(selectLabel); listPanel.add(wsdlMethods); listPanel.add(selectButton); selectButton.addActionListener(this); topPanel.add(wsdlHelper); JPanel urlPane = new JPanel(); urlPane.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); urlPane.add(protocol); urlPane.add(Box.createRigidArea(new Dimension(5, 0))); urlPane.add(domain); urlPane.add(Box.createRigidArea(new Dimension(5, 0))); urlPane.add(port); urlPane.add(Box.createRigidArea(new Dimension(5, 0))); urlPane.add(connectTimeout); topPanel.add(urlPane); topPanel.add(createParametersPanel()); return topPanel; }
From source file:org.obiba.onyx.jade.instrument.ricelake.RiceLakeWeightInstrumentRunner.java
/** * Build action buttons sub panel/* w w w . j a v a2 s .c om*/ */ protected JPanel buildActionButtonSubPanel() { JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.add(Box.createHorizontalGlue()); panel.add(saveButton); JButton resetButton = new JButton(resourceBundle.getString("Reset")); resetButton.setMnemonic('R'); resetButton.setToolTipText(resourceBundle.getString("ToolTip.Reset_measurement")); panel.add(Box.createRigidArea(new Dimension(10, 0))); panel.add(resetButton); JButton cancelButton = new JButton(resourceBundle.getString("Cancel")); cancelButton.setMnemonic('A'); cancelButton.setToolTipText(resourceBundle.getString("ToolTip.Cancel_measurement")); panel.add(Box.createRigidArea(new Dimension(10, 0))); panel.add(cancelButton); JButton configureButton = new JButton(resourceBundle.getString("Configure")); configureButton.setMnemonic('C'); configureButton.setToolTipText(resourceBundle.getString("ToolTip.Configure")); panel.add(Box.createRigidArea(new Dimension(10, 0))); panel.add(configureButton); // Configure button listener configureButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { configure(); } }); // Reset button listener resetButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { clearData(); } }); // Save button listener. saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sendOutputToServer(); } }); // Cancel button listener. cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { confirmOnExit(); } }); panel.setAlignmentX(Component.LEFT_ALIGNMENT); return (panel); }
From source file:net.sf.vfsjfilechooser.plaf.metal.MetalVFSFileChooserUI.java
@SuppressWarnings("serial") @Override/* ww w . j av a 2 s . c o m*/ public void installComponents(VFSJFileChooser fc) { AbstractVFSFileSystemView fsv = fc.getFileSystemView(); fc.setBorder(new EmptyBorder(12, 12, 11, 11)); fc.setLayout(new BorderLayout(0, 11)); filePane = new VFSFilePane(new MetalVFSFileChooserUIAccessor()); fc.addPropertyChangeListener(filePane); updateUseShellFolder(); // ********************************* // // **** Construct the top panel **** // // ********************************* // // Directory manipulation buttons JPanel topPanel = new JPanel(new BorderLayout(11, 0)); topButtonPanel = new JPanel(); topButtonPanel.setLayout(new BoxLayout(topButtonPanel, BoxLayout.LINE_AXIS)); topPanel.add(topButtonPanel, BorderLayout.AFTER_LINE_ENDS); // Add the top panel to the fileChooser fc.add(topPanel, BorderLayout.NORTH); // ComboBox Label lookInLabel = new JLabel(lookInLabelText); topPanel.add(lookInLabel, BorderLayout.BEFORE_LINE_BEGINS); // CurrentDir ComboBox directoryComboBox = new JComboBox() { @Override public Dimension getPreferredSize() { Dimension d = super.getPreferredSize(); // Must be small enough to not affect total width. d.width = 150; return d; } }; directoryComboBox.putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY, lookInLabelText); directoryComboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); lookInLabel.setLabelFor(directoryComboBox); directoryComboBoxModel = createDirectoryComboBoxModel(fc); directoryComboBox.setModel(directoryComboBoxModel); directoryComboBox.addActionListener(directoryComboBoxAction); directoryComboBox.setRenderer(createDirectoryComboBoxRenderer(fc)); directoryComboBox.setAlignmentX(JComponent.LEFT_ALIGNMENT); directoryComboBox.setAlignmentY(JComponent.TOP_ALIGNMENT); directoryComboBox.setMaximumRowCount(8); topPanel.add(directoryComboBox, BorderLayout.CENTER); // Up Button upFolderButton = new JButton(getChangeToParentDirectoryAction()); upFolderButton.setText(null); upFolderButton.setIcon(upFolderIcon); upFolderButton.setToolTipText(upFolderToolTipText); upFolderButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, upFolderAccessibleName); upFolderButton.setAlignmentX(JComponent.LEFT_ALIGNMENT); upFolderButton.setAlignmentY(JComponent.CENTER_ALIGNMENT); upFolderButton.setMargin(shrinkwrap); topButtonPanel.add(upFolderButton); topButtonPanel.add(Box.createRigidArea(hstrut5)); // Home Button FileObject homeDir = fsv.getHomeDirectory(); String toolTipText = homeFolderToolTipText; if (fsv.isRoot(homeDir)) { toolTipText = getFileView(fc).getName(homeDir); // Probably "Desktop". } JButton b = new JButton(homeFolderIcon); b.setToolTipText(toolTipText); b.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, homeFolderAccessibleName); b.setAlignmentX(JComponent.LEFT_ALIGNMENT); b.setAlignmentY(JComponent.CENTER_ALIGNMENT); b.setMargin(shrinkwrap); b.addActionListener(getGoHomeAction()); topButtonPanel.add(b); topButtonPanel.add(Box.createRigidArea(hstrut5)); // New Directory Button if (!UIManager.getBoolean("FileChooser.readOnly")) { b = new JButton(filePane.getNewFolderAction()); b.setText(null); b.setIcon(newFolderIcon); b.setToolTipText(newFolderToolTipText); b.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, newFolderAccessibleName); b.setAlignmentX(JComponent.LEFT_ALIGNMENT); b.setAlignmentY(JComponent.CENTER_ALIGNMENT); b.setMargin(shrinkwrap); } topButtonPanel.add(b); topButtonPanel.add(Box.createRigidArea(hstrut5)); // View button group ButtonGroup viewButtonGroup = new ButtonGroup(); // List Button listViewButton = new JToggleButton(listViewIcon); listViewButton.setToolTipText(listViewButtonToolTipText); listViewButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, listViewButtonAccessibleName); listViewButton.setSelected(true); listViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT); listViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT); listViewButton.setMargin(shrinkwrap); listViewButton.addActionListener(filePane.getViewTypeAction(VFSFilePane.VIEWTYPE_LIST)); topButtonPanel.add(listViewButton); viewButtonGroup.add(listViewButton); // Details Button detailsViewButton = new JToggleButton(detailsViewIcon); detailsViewButton.setToolTipText(detailsViewButtonToolTipText); detailsViewButton.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, detailsViewButtonAccessibleName); detailsViewButton.setAlignmentX(JComponent.LEFT_ALIGNMENT); detailsViewButton.setAlignmentY(JComponent.CENTER_ALIGNMENT); detailsViewButton.setMargin(shrinkwrap); detailsViewButton.addActionListener(filePane.getViewTypeAction(VFSFilePane.VIEWTYPE_DETAILS)); topButtonPanel.add(detailsViewButton); viewButtonGroup.add(detailsViewButton); filePane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { if ("viewType".equals(e.getPropertyName())) { final int viewType = filePane.getViewType(); if (viewType == VFSFilePane.VIEWTYPE_LIST) { listViewButton.setSelected(true); } else if (viewType == VFSFilePane.VIEWTYPE_DETAILS) { detailsViewButton.setSelected(true); } } } }); // ************************************** // // ******* Add the directory pane ******* // // ************************************** // fc.add(getAccessoryPanel(), BorderLayout.AFTER_LINE_ENDS); JComponent accessory = fc.getAccessory(); if (accessory != null) { getAccessoryPanel().add(accessory); } filePane.setPreferredSize(LIST_PREF_SIZE); fc.add(filePane, BorderLayout.CENTER); // ********************************** // // **** Construct the bottom panel ** // // ********************************** // bottomPanel = getBottomPanel(); bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.Y_AXIS)); fc.add(bottomPanel, BorderLayout.SOUTH); // FileName label and textfield JPanel fileNamePanel = new JPanel(); fileNamePanel.setLayout(new BoxLayout(fileNamePanel, BoxLayout.LINE_AXIS)); bottomPanel.add(fileNamePanel); bottomPanel.add(Box.createRigidArea(vstrut5)); fileNameLabel = new AlignedLabel(); populateFileNameLabel(); fileNamePanel.add(fileNameLabel); fileNameTextField = new JTextField(35) { @Override public Dimension getMaximumSize() { return new Dimension(Short.MAX_VALUE, super.getPreferredSize().height); } }; PopupHandler.installDefaultMouseListener(fileNameTextField); fileNamePanel.add(fileNameTextField); fileNameLabel.setLabelFor(fileNameTextField); fileNameTextField.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { if (!getFileChooser().isMultiSelectionEnabled()) { filePane.clearSelection(); } } }); if (fc.isMultiSelectionEnabled()) { setFileName(fileNameString(fc.getSelectedFiles())); } else { setFileName(fileNameString(fc.getSelectedFile())); } // Filetype label and combobox JPanel filesOfTypePanel = new JPanel(); filesOfTypePanel.setLayout(new BoxLayout(filesOfTypePanel, BoxLayout.LINE_AXIS)); bottomPanel.add(filesOfTypePanel); AlignedLabel filesOfTypeLabel = new AlignedLabel(filesOfTypeLabelText); filesOfTypePanel.add(filesOfTypeLabel); filterComboBoxModel = createFilterComboBoxModel(); fc.addPropertyChangeListener(filterComboBoxModel); filterComboBox = new JComboBox(filterComboBoxModel); filterComboBox.putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY, filesOfTypeLabelText); filesOfTypeLabel.setLabelFor(filterComboBox); filterComboBox.setRenderer(createFilterComboBoxRenderer()); filesOfTypePanel.add(filterComboBox); // buttons getButtonPanel().setLayout(new ButtonAreaLayout()); approveButton = new JButton(getApproveButtonText(fc)); // Note: Metal does not use mnemonics for approve and cancel approveButton.addActionListener(getApproveSelectionAction()); fileNameTextField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { getApproveSelectionAction().actionPerformed(null); } } }); approveButton.setToolTipText(getApproveButtonToolTipText(fc)); getButtonPanel().add(approveButton); cancelButton = new JButton(cancelButtonText); cancelButton.setToolTipText(cancelButtonToolTipText); cancelButton.addActionListener(getCancelSelectionAction()); getButtonPanel().add(cancelButton); if (fc.getControlButtonsAreShown()) { addControlButtons(); } groupLabels(new AlignedLabel[] { fileNameLabel, filesOfTypeLabel }); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.util.MoveGroupSelectionDialog.java
/** * Builds and lays out the buttons./* www . j av a2 s .c o m*/ * * @return See above. */ private JPanel buildToolBar() { JPanel bar = new JPanel(); bar.add(moveButton); bar.add(Box.createRigidArea(UIUtilities.H_SPACER_SIZE)); bar.add(cancelButton); bar.add(Box.createRigidArea(UIUtilities.H_SPACER_SIZE)); JPanel barLeft = new JPanel(); barLeft.add(createButton); JPanel row = new JPanel(); row.setLayout(new BoxLayout(row, BoxLayout.X_AXIS)); row.add(UIUtilities.buildComponentPanel(barLeft)); row.add(UIUtilities.buildComponentPanelRight(bar)); return row; }