List of usage examples for javax.swing JPanel setLayout
public void setLayout(LayoutManager mgr)
From source file:OptionDialogTest.java
public OptionDialogFrame() { setTitle("OptionDialogTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JPanel gridPanel = new JPanel(); gridPanel.setLayout(new GridLayout(2, 3)); typePanel = new ButtonPanel("Type", "Message", "Confirm", "Option", "Input"); messageTypePanel = new ButtonPanel("Message Type", "ERROR_MESSAGE", "INFORMATION_MESSAGE", "WARNING_MESSAGE", "QUESTION_MESSAGE", "PLAIN_MESSAGE"); messagePanel = new ButtonPanel("Message", "String", "Icon", "Component", "Other", "Object[]"); optionTypePanel = new ButtonPanel("Confirm", "DEFAULT_OPTION", "YES_NO_OPTION", "YES_NO_CANCEL_OPTION", "OK_CANCEL_OPTION"); optionsPanel = new ButtonPanel("Option", "String[]", "Icon[]", "Object[]"); inputPanel = new ButtonPanel("Input", "Text field", "Combo box"); gridPanel.add(typePanel);//from ww w . j a v a2s .co m gridPanel.add(messageTypePanel); gridPanel.add(messagePanel); gridPanel.add(optionTypePanel); gridPanel.add(optionsPanel); gridPanel.add(inputPanel); // add a panel with a Show button JPanel showPanel = new JPanel(); JButton showButton = new JButton("Show"); showButton.addActionListener(new ShowAction()); showPanel.add(showButton); add(gridPanel, BorderLayout.CENTER); add(showPanel, BorderLayout.SOUTH); }
From source file:VoteDialog.java
private JPanel createPane(String description, JRadioButton[] radioButtons, JButton showButton) { int numChoices = radioButtons.length; JPanel box = new JPanel(); JLabel label = new JLabel(description); box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS)); box.add(label);//from ww w. ja va 2s. c o m for (int i = 0; i < numChoices; i++) { box.add(radioButtons[i]); } JPanel pane = new JPanel(); pane.setLayout(new BorderLayout()); pane.add(box, BorderLayout.NORTH); pane.add(showButton, BorderLayout.SOUTH); System.out.println("returning pane"); return pane; }
From source file:gda.util.userOptions.UserOptionsDialog.java
/** * @param frame//from www . j a v a2 s.co m * @param parent * @param options */ public UserOptionsDialog(JFrame frame, Component parent, UserOptions options) { super(frame, options.title, true); this.frame = frame; this.options = options; JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); label = new JLabel(options.title != null ? options.title : ""); label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); label.setAlignmentX(Component.CENTER_ALIGNMENT); JPanel pane = makePane(); // pane.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); pane.setAlignmentX(Component.CENTER_ALIGNMENT); // pane.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); panel.add(label); panel.add(pane); JPanel btnPanel = new JPanel(); btnPanel.setLayout(new BoxLayout(btnPanel, BoxLayout.X_AXIS)); JButton okButton = new JButton("OK"); okButton.addActionListener(this); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(this); JButton defButton = new JButton("Default"); defButton.addActionListener(this); JButton resetButton = new JButton("Reset"); resetButton.addActionListener(this); btnPanel.add(Box.createHorizontalGlue()); btnPanel.add(okButton); btnPanel.add(Box.createHorizontalGlue()); btnPanel.add(cancelButton); btnPanel.add(Box.createHorizontalGlue()); btnPanel.add(defButton); btnPanel.add(Box.createHorizontalGlue()); btnPanel.add(resetButton); btnPanel.add(Box.createHorizontalGlue()); btnPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); panel.add(btnPanel); getContentPane().add(panel); getRootPane().setDefaultButton(cancelButton); pack(); setLocationRelativeTo(parent); setVisible(true); setDefaultCloseOperation(DISPOSE_ON_CLOSE); }
From source file:ColorMenu.java
public ColorMenu(String name) { super(name);//from w w w .j ava2s. co m _unselectedBorder = new CompoundBorder(new MatteBorder(1, 1, 1, 1, getBackground()), new BevelBorder(BevelBorder.LOWERED, Color.WHITE, Color.GRAY)); _selectedBorder = new CompoundBorder(new MatteBorder(2, 2, 2, 2, Color.RED), new MatteBorder(1, 1, 1, 1, getBackground())); _activeBorder = new CompoundBorder(new MatteBorder(2, 2, 2, 2, Color.BLUE), new MatteBorder(1, 1, 1, 1, getBackground())); JPanel p = new JPanel(); p.setBorder(new EmptyBorder(5, 5, 5, 5)); p.setLayout(new GridLayout(8, 8)); _colorPanes = new HashMap(); int values[] = new int[] { 0, 128, 192, 255 }; for (int r = 0; r < values.length; r++) for (int g = 0; g < values.length; g++) for (int b = 0; b < values.length; b++) { Color color = new Color(values[r], values[g], values[b]); ColorPane colorPane = new ColorPane(color); p.add(colorPane); _colorPanes.put(color, colorPane); } add(p); }
From source file:com.intel.stl.ui.monitor.view.PSEventsPieChart.java
protected JPanel getLengendPanel() { JPanel panel = new JPanel(); panel.setOpaque(false);/*from w w w.j a v a2s. co m*/ panel.setLayout(new GridBagLayout()); GridBagConstraints gc = new GridBagConstraints(); gc.fill = GridBagConstraints.BOTH; StateLongTypeViz[] states = StateLongTypeViz.values(); stateLabels = new JLabel[states.length]; for (int i = 0; i < states.length; i++) { StateLongTypeViz state = states[i]; gc.insets = new Insets(2, 5, 2, 2); gc.weightx = 0; gc.gridwidth = 1; JLabel label = new JLabel(state.getName(), Util.generateImageIcon(state.getColor(), 8, new Insets(1, 1, 1, 1)), JLabel.LEFT); label.setFont(UIConstants.H5_FONT); label.setForeground(UIConstants.INTEL_DARK_GRAY); panel.add(label, gc); gc.gridwidth = GridBagConstraints.REMAINDER; gc.weightx = 0; stateLabels[i] = new JLabel(); stateLabels[i].setForeground(UIConstants.INTEL_DARK_GRAY); stateLabels[i].setFont(UIConstants.H5_FONT); panel.add(stateLabels[i], gc); } return panel; }
From source file:com.digitalgeneralists.assurance.ui.components.FilePickerTextField.java
protected void initializeComponent() { if (!this.initialized) { this.filePicker.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); GridBagLayout gridbag = new GridBagLayout(); this.setLayout(gridbag); final JPanel filePathPanel = new JPanel(); filePathPanel.setLayout(new GridBagLayout()); GridBagConstraints filePathPanelConstraints = new GridBagConstraints(); filePathPanelConstraints.anchor = GridBagConstraints.NORTH; filePathPanelConstraints.fill = GridBagConstraints.HORIZONTAL; filePathPanelConstraints.gridx = 0; filePathPanelConstraints.gridy = 0; filePathPanelConstraints.weightx = 1.0; filePathPanelConstraints.weighty = 1.0; filePathPanelConstraints.gridheight = 1; filePathPanelConstraints.gridwidth = 2; filePathPanelConstraints.insets = new Insets(0, 0, 0, 0); GridBagConstraints pathTextFieldConstraints = new GridBagConstraints(); pathTextFieldConstraints.anchor = GridBagConstraints.NORTH; pathTextFieldConstraints.fill = GridBagConstraints.HORIZONTAL; pathTextFieldConstraints.gridx = 0; pathTextFieldConstraints.gridy = 0; pathTextFieldConstraints.weightx = 0.9; pathTextFieldConstraints.weighty = 1.0; pathTextFieldConstraints.gridheight = 1; pathTextFieldConstraints.gridwidth = 1; pathTextFieldConstraints.insets = new Insets(0, 0, 0, 0); GridBagConstraints pathFileChooserButtonConstraints = new GridBagConstraints(); pathFileChooserButtonConstraints.anchor = GridBagConstraints.NORTH; pathFileChooserButtonConstraints.fill = GridBagConstraints.HORIZONTAL; pathFileChooserButtonConstraints.gridx = 1; pathFileChooserButtonConstraints.gridy = 0; pathFileChooserButtonConstraints.weightx = 0.1; pathFileChooserButtonConstraints.weighty = 1.0; pathFileChooserButtonConstraints.gridheight = 1; pathFileChooserButtonConstraints.gridwidth = 1; pathFileChooserButtonConstraints.insets = new Insets(0, 0, 0, 0); filePathPanel.add(this.pathTextField, pathTextFieldConstraints); filePathPanel.add(this.pathFileChooserButton, pathFileChooserButtonConstraints); this.add(filePathPanel, filePathPanelConstraints); this.pathFileChooserButton.setActionCommand(AssuranceActions.chooseFilePathAction); this.pathTextField.getDocument().addDocumentListener(this.textPropertyValidationListener); this.pathFileChooserButton.addActionListener(this); this.initialized = true; }/*from w w w .j a va2 s. c o m*/ }
From source file:com.stefanbrenner.droplet.ui.DevicePanel.java
/** * Create the panel./*from w w w. j a v a 2s. c om*/ */ public DevicePanel(final JComponent parent, final IDroplet droplet, final T device) { this.parent = parent; setDevice(device); setLayout(new BorderLayout(0, 5)); setBorder(BorderFactory.createLineBorder(Color.BLACK)); setBackground(DropletColors.getBackgroundColor(device)); BeanAdapter<T> adapter = new BeanAdapter<T>(device, true); // device name textfield txtName = BasicComponentFactory.createTextField(adapter.getValueModel(IDevice.PROPERTY_NAME)); txtName.setHorizontalAlignment(SwingConstants.CENTER); txtName.setColumns(1); txtName.setToolTipText(device.getName()); adapter.addBeanPropertyChangeListener(IDevice.PROPERTY_NAME, new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent event) { txtName.setToolTipText(device.getName()); } }); add(txtName, BorderLayout.NORTH); // actions panel with scroll pane actionsPanel = new JPanel(); actionsPanel.setLayout(new BoxLayout(actionsPanel, BoxLayout.Y_AXIS)); actionsPanel.setBackground(getBackground()); JScrollPane scrollPane = new JScrollPane(actionsPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); // resize vertical scrollbar scrollPane.getVerticalScrollBar().putClientProperty("JComponent.sizeVariant", "mini"); //$NON-NLS-1$ //$NON-NLS-2$ SwingUtilities.updateComponentTreeUI(scrollPane); // we need no border scrollPane.setBorder(BorderFactory.createEmptyBorder()); add(scrollPane, BorderLayout.CENTER); { JPanel panel = new JPanel(); panel.setLayout(new GridLayout(0, 1)); createAddButton(panel); // remove button JButton btnRemove = new JButton(Messages.getString("ActionDevicePanel.removeDevice")); //$NON-NLS-1$ btnRemove.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent action) { int retVal = JOptionPane.showConfirmDialog(DevicePanel.this, Messages.getString("ActionDevicePanel.removeDevice") + " '" + device.getName() + "'?", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ StringUtils.EMPTY, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (retVal == JOptionPane.YES_OPTION) { droplet.removeDevice(device); } } }); btnRemove.setFocusable(false); panel.add(btnRemove); add(panel, BorderLayout.SOUTH); } }
From source file:de.codesourcery.eve.skills.ui.components.ListEditingComponent.java
@Override protected final JPanel createPanel() { final JPanel result = new JPanel(); result.setLayout(new BorderLayout()); final JScrollPane scrollPane = new JScrollPane(list); if (!StringUtils.isBlank(getTitle())) { scrollPane.setBorder(BorderFactory.createTitledBorder(getTitle())); }// w w w. j av a 2s. co m scrollPane.setPreferredSize(new Dimension(150, 400)); result.add(scrollPane, BorderLayout.NORTH); final JPanel buttonPanel = new JPanel(); populateButtonPanel(buttonPanel); result.add(buttonPanel, BorderLayout.SOUTH); createPanelHook(result); return result; }
From source file:DataExchangeTest.java
public PasswordChooser() { setLayout(new BorderLayout()); // construct a panel with user name and password fields JPanel panel = new JPanel(); panel.setLayout(new GridLayout(2, 2)); panel.add(new JLabel("User name:")); panel.add(username = new JTextField("")); panel.add(new JLabel("Password:")); panel.add(password = new JPasswordField("")); add(panel, BorderLayout.CENTER); // create Ok and Cancel buttons that terminate the dialog okButton = new JButton("Ok"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { ok = true;/*from w w w . ja v a 2 s.c o m*/ dialog.setVisible(false); } }); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { dialog.setVisible(false); } }); // add buttons to southern border JPanel buttonPanel = new JPanel(); buttonPanel.add(okButton); buttonPanel.add(cancelButton); add(buttonPanel, BorderLayout.SOUTH); }
From source file:Visuals.BarChart.java
public JPanel addCharts() { ChartPanel barPanel = drawBarChart(); barPanel.setDomainZoomable(true);/*from w w w .j av a 2 s . c om*/ JPanel thisBarPanel = new JPanel(); thisBarPanel.setLayout(new BorderLayout()); String[][] finalRisks = new String[riskCount][4]; for (int i = 0; i < riskCount; i++) { finalRisks[i][0] = risks[i][0]; finalRisks[i][1] = risks[i][1]; finalRisks[i][2] = risks[i][2]; finalRisks[i][3] = risks[i][3]; } JTable table = new JTable(finalRisks, columns); //table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); TableRowSorter<TableModel> sorter = new TableRowSorter<>(table.getModel()); table.setRowSorter(sorter); List<RowSorter.SortKey> sortKeys = new ArrayList<>(); int columnIndexToSort = 2; sortKeys.add(new RowSorter.SortKey(columnIndexToSort, SortOrder.ASCENDING)); sorter.setSortKeys(sortKeys); sorter.sort(); TableColumn tcol = table.getColumnModel().getColumn(2); table.removeColumn(tcol); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.getColumnModel().getColumn(1).setPreferredWidth(600); table.getColumnModel().getColumn(2).setPreferredWidth(600); table.setShowHorizontalLines(true); table.setRowHeight(40); table.setEnabled(false); JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); Dimension d = table.getPreferredSize(); tableScrollPane .setPreferredSize(new Dimension((d.width - 400), (table.getRowHeight() + 1) * (riskCount + 1))); JLabel right = new JLabel( " "); thisBarPanel.add(right, BorderLayout.EAST); thisBarPanel.add(barPanel, BorderLayout.CENTER); thisBarPanel.add(tableScrollPane, BorderLayout.SOUTH); return thisBarPanel; }