List of usage examples for javax.swing JComboBox setMaximumSize
@BeanProperty(description = "The maximum size of the component.") public void setMaximumSize(Dimension maximumSize)
From source file:Main.java
public static void main(String[] argv) throws Exception { JToolBar toolbar = new JToolBar(); ImageIcon icon = new ImageIcon("icon.gif"); Action action = new AbstractAction("Button Label", icon) { public void actionPerformed(ActionEvent evt) { }// w ww . jav a 2 s. co m }; JButton c1 = new JButton(action); c1.setText(null); c1.setMargin(new Insets(0, 0, 0, 0)); toolbar.add(c1); JToggleButton c2 = new JToggleButton(action); c2.setText(null); c2.setMargin(new Insets(0, 0, 0, 0)); toolbar.add(c2); JComboBox c3 = new JComboBox(new String[] { "A", "B", "C" }); c3.setPrototypeDisplayValue("XXXXXXXX"); // Set a desired width c3.setMaximumSize(c3.getMinimumSize()); toolbar.add(c3); }
From source file:com.game.ui.views.PlayerEditor.java
public void doGui() { // setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); setLayout(new GridBagLayout()); GridBagConstraints c1 = new GridBagConstraints(); c1.fill = GridBagConstraints.NONE; c1.anchor = GridBagConstraints.WEST; c1.insets = new Insets(10, 5, 10, 5); c1.weightx = 0;//ww w .j a v a 2 s. c o m c1.weighty = 0; JLabel noteLbl = new JLabel("Pls select a value to choose a Player or you can create a new " + "Player entity below. Once selected a Player character, its' details will be available below"); add(noteLbl, c1); DefaultComboBoxModel model = new DefaultComboBoxModel(); for (GameCharacter character : GameBean.playerDetails) { model.addElement(((Player) character).getType()); } c1.gridy = 1; comboBox = new JComboBox(model); comboBox.setSelectedIndex(-1); comboBox.setMaximumSize(new Dimension(100, 30)); comboBox.setActionCommand("dropDown"); comboBox.addActionListener(this); add(comboBox, c1); JPanel wrapperPanel = new JPanel(new GridLayout(1, 2, 10, 10)); wrapperPanel.setBorder(LineBorder.createGrayLineBorder()); leftPanel = new JPanel(); leftPanel.setAlignmentX(0); leftPanel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(5, 5, 5, 5); c.weightx = 1; c.weighty = 1; c.gridwidth = 2; JLabel enemyDtlLbl = new JLabel("Enemy Character Details : "); enemyDtlLbl.setFont(new Font("Times New Roman", Font.BOLD, 15)); leftPanel.add(enemyDtlLbl, c); c.gridwidth = 1; c.gridy = 1; JLabel nameLbl = new JLabel("Name : "); leftPanel.add(nameLbl, c); c.gridx = 1; JTextField name = new JTextField(""); name.setColumns(20); leftPanel.add(name, c); c.gridx = 0; c.gridy = 2; JLabel imageLbl = new JLabel("Image Path : "); leftPanel.add(imageLbl, c); c.gridx = 1; JTextField image = new JTextField(""); image.setColumns(20); leftPanel.add(image, c); c.gridx = 0; c.gridy = 3; JLabel healthLbl = new JLabel("Health Pts : "); leftPanel.add(healthLbl, c); c.gridx = 1; JTextField health = new JTextField(""); health.setColumns(20); leftPanel.add(health, c); c.gridx = 0; c.gridy = 4; JLabel attackPtsLbl = new JLabel("Attack Points : "); leftPanel.add(attackPtsLbl, c); c.gridx = 1; JTextField attackPts = new JTextField(""); attackPts.setColumns(20); leftPanel.add(attackPts, c); c.gridx = 0; c.gridy = 5; JLabel armoursPtsLbl = new JLabel("Armour Points : "); leftPanel.add(armoursPtsLbl, c); c.gridx = 1; JTextField armourPts = new JTextField(""); armourPts.setColumns(20); leftPanel.add(armourPts, c); c.gridx = 0; c.gridy = 6; JLabel attackRngeLbl = new JLabel("Attack Range : "); leftPanel.add(attackRngeLbl, c); c.gridx = 1; JTextField attackRnge = new JTextField(""); attackRnge.setColumns(20); leftPanel.add(attackRnge, c); c.gridx = 0; c.gridy = 7; JLabel movementLbl = new JLabel("Movement : "); leftPanel.add(movementLbl, c); c.gridx = 1; JTextField movement = new JTextField(""); movement.setColumns(20); leftPanel.add(movement, c); c.gridx = 0; c.gridy = 8; JLabel typeLbl = new JLabel("Type : "); leftPanel.add(typeLbl, c); c.gridx = 1; JTextField typeTxt = new JTextField(""); typeTxt.setColumns(20); leftPanel.add(typeTxt, c); c.gridx = 0; c.gridy = 9; JLabel weaponLbl = new JLabel("Equipped Weapon : "); leftPanel.add(weaponLbl, c); c.gridx = 1; DefaultComboBoxModel weapon = new DefaultComboBoxModel(); for (Item item : GameBean.weaponDetails) { if (item instanceof Weapon) { weapon.addElement(((Weapon) item).getName()); } } JComboBox weaponDrpDown = new JComboBox(weapon); weaponDrpDown.setSelectedIndex(-1); weaponDrpDown.setMaximumSize(new Dimension(100, 30)); leftPanel.add(weaponDrpDown, c); c.gridx = 0; c.gridy = 10; c.gridwidth = 2; JButton submit = new JButton("Save"); submit.addActionListener(this); submit.setActionCommand("button"); leftPanel.add(submit, c); wrapperPanel.add(leftPanel); lvlPanel = new LevelPanel(true, null); wrapperPanel.add(lvlPanel); c1.gridy = 2; c1.fill = GridBagConstraints.BOTH; add(wrapperPanel, c1); c1.fill = GridBagConstraints.NONE; validationMess = new JLabel("Pls enter all the fields or pls choose a character from the drop down"); validationMess.setForeground(Color.red); validationMess.setVisible(false); c1.gridy = 3; add(validationMess, c1); c1.weightx = 1; c1.fill = GridBagConstraints.BOTH; c1.weighty = 1; c1.gridy = 4; add(new JPanel(), c1); }
From source file:ec.util.chart.swing.JTimeSeriesRendererSupportDemo.java
private Component createToolBar() { JToolBar result = new JToolBar(); result.setFloatable(false);/* ww w. java 2 s . c o m*/ result.add(RANDOM_DATA.toAction(chart)).setIcon(FontAwesome.FA_RANDOM.getIcon(getForeground(), 16f)); JComboBox<RendererType> types = new JComboBox<>( support.getSupportedRendererTypes().toArray(new RendererType[0])); types.setMaximumSize(new Dimension(150, 100)); types.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { RendererType type = (RendererType) e.getItem(); chart.getXYPlot().setRenderer(support.createRenderer(type)); chart.getXYPlot().setBackgroundPaint(support.getPlotColor()); chart.setBackgroundPaint(colorSchemeSupport.getBackColor()); } }); types.setSelectedIndex(1); result.add(types); return result; }
From source file:net.pandoragames.far.ui.swing.dialog.SettingsDialog.java
private void init() { this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS)); this.setResizable(false); JPanel basePanel = new JPanel(); basePanel.setLayout(new BoxLayout(basePanel, BoxLayout.Y_AXIS)); basePanel.setBorder(//from www . j a v a 2 s . c om BorderFactory.createEmptyBorder(0, SwingConfig.PADDING, SwingConfig.PADDING, SwingConfig.PADDING)); registerCloseWindowKeyListener(basePanel); // sink for error messages MessageLabel errorField = new MessageLabel(); errorField.setMinimumSize(new Dimension(100, swingConfig.getStandardComponentHight())); errorField.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING)); TwoComponentsPanel lineError = new TwoComponentsPanel(errorField, Box.createRigidArea(new Dimension(1, swingConfig.getStandardComponentHight()))); lineError.setAlignmentX(Component.LEFT_ALIGNMENT); basePanel.add(lineError); // character set JLabel labelCharset = new JLabel(swingConfig.getLocalizer().localize("label.default-characterset")); labelCharset.setAlignmentX(Component.LEFT_ALIGNMENT); basePanel.add(labelCharset); JComboBox listCharset = new JComboBox(swingConfig.getCharsetList().toArray()); listCharset.setAlignmentX(Component.LEFT_ALIGNMENT); listCharset.setSelectedItem(swingConfig.getDefaultCharset()); listCharset.setEditable(true); listCharset.setMaximumSize( new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, swingConfig.getStandardComponentHight())); listCharset.addActionListener(new CharacterSetListener(errorField)); listCharset.setEditor(new CharacterSetEditor(errorField)); basePanel.add(listCharset); basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING))); // select the group selector JPanel selectorPanel = new JPanel(); selectorPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); selectorPanel.setAlignmentX(Component.LEFT_ALIGNMENT); // linePattern.setAlignmentX( Component.LEFT_ALIGNMENT ); JLabel labelSelector = new JLabel(swingConfig.getLocalizer().localize("label.group-ref-indicator")); selectorPanel.add(labelSelector); JComboBox selectorBox = new JComboBox(FARConfig.GROUPREFINDICATORLIST); selectorBox.setSelectedItem(Character.toString(groupReference)); selectorBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JComboBox cbox = (JComboBox) event.getSource(); String indicator = (String) cbox.getSelectedItem(); groupReference = indicator.charAt(0); } }); selectorPanel.add(selectorBox); basePanel.add(selectorPanel); basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING))); // checkbox DO BACKUP JCheckBox doBackupFlag = new JCheckBox(swingConfig.getLocalizer().localize("label.create-backup")); doBackupFlag.setAlignmentX(Component.LEFT_ALIGNMENT); doBackupFlag.setHorizontalTextPosition(SwingConstants.LEADING); doBackupFlag.setSelected(replaceForm.isDoBackup()); doBackupFlag.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { doBackup = ItemEvent.SELECTED == event.getStateChange(); backupFlagEvent = event; } }); basePanel.add(doBackupFlag); JTextField backupDirPathTextField = new JTextField(); backupDirPathTextField.setPreferredSize( new Dimension(SwingConfig.COMPONENT_WIDTH, swingConfig.getStandardComponentHight())); backupDirPathTextField.setMaximumSize( new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, swingConfig.getStandardComponentHight())); backupDirPathTextField.setText(backupDirectory.getPath()); backupDirPathTextField.setToolTipText(backupDirectory.getPath()); backupDirPathTextField.setEditable(false); JButton openBaseDirFileChooserButton = new JButton(swingConfig.getLocalizer().localize("button.browse")); BrowseButtonListener backupDirButtonListener = new BrowseButtonListener(backupDirPathTextField, new BackUpDirectoryRepository(swingConfig, findForm, replaceForm, errorField), swingConfig.getLocalizer().localize("label.choose-backup-directory")); openBaseDirFileChooserButton.addActionListener(backupDirButtonListener); TwoComponentsPanel lineBaseDir = new TwoComponentsPanel(backupDirPathTextField, openBaseDirFileChooserButton); lineBaseDir.setAlignmentX(Component.LEFT_ALIGNMENT); basePanel.add(lineBaseDir); basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING))); JPanel fileInfoPanel = new JPanel(); fileInfoPanel .setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), swingConfig.getLocalizer().localize("label.default-file-info"))); fileInfoPanel.setAlignmentX(Component.LEFT_ALIGNMENT); fileInfoPanel.setLayout(new BoxLayout(fileInfoPanel, BoxLayout.Y_AXIS)); JLabel fileInfoLabel = new JLabel(swingConfig.getLocalizer().localize("message.displayed-in-info-column")); fileInfoLabel.setAlignmentX(Component.LEFT_ALIGNMENT); fileInfoPanel.add(fileInfoLabel); fileInfoPanel.add(Box.createHorizontalGlue()); JRadioButton nothingRadio = new JRadioButton(swingConfig.getLocalizer().localize("label.nothing")); nothingRadio.setAlignmentX(Component.LEFT_ALIGNMENT); nothingRadio.setActionCommand(SwingConfig.DefaultFileInfo.NOTHING.name()); nothingRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.NOTHING); fileInfoOptions.add(nothingRadio); fileInfoPanel.add(nothingRadio); JRadioButton readOnlyRadio = new JRadioButton( swingConfig.getLocalizer().localize("label.read-only-warning")); readOnlyRadio.setAlignmentX(Component.LEFT_ALIGNMENT); readOnlyRadio.setActionCommand(SwingConfig.DefaultFileInfo.READONLY.name()); readOnlyRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.READONLY); fileInfoOptions.add(readOnlyRadio); fileInfoPanel.add(readOnlyRadio); JRadioButton sizeRadio = new JRadioButton(swingConfig.getLocalizer().localize("label.filesize")); sizeRadio.setAlignmentX(Component.LEFT_ALIGNMENT); sizeRadio.setActionCommand(SwingConfig.DefaultFileInfo.SIZE.name()); sizeRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.SIZE); fileInfoOptions.add(sizeRadio); fileInfoPanel.add(sizeRadio); JCheckBox showPlainBytesFlag = new JCheckBox( " " + swingConfig.getLocalizer().localize("label.show-plain-bytes")); showPlainBytesFlag.setAlignmentX(Component.LEFT_ALIGNMENT); showPlainBytesFlag.setHorizontalTextPosition(SwingConstants.LEADING); showPlainBytesFlag.setSelected(swingConfig.isShowPlainBytes()); showPlainBytesFlag.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { showBytes = ItemEvent.SELECTED == event.getStateChange(); } }); fileInfoPanel.add(showPlainBytesFlag); JRadioButton lastModifiedRadio = new JRadioButton( swingConfig.getLocalizer().localize("label.last-modified")); lastModifiedRadio.setAlignmentX(Component.LEFT_ALIGNMENT); lastModifiedRadio.setActionCommand(SwingConfig.DefaultFileInfo.LAST_MODIFIED.name()); lastModifiedRadio .setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.LAST_MODIFIED); fileInfoOptions.add(lastModifiedRadio); fileInfoPanel.add(lastModifiedRadio); basePanel.add(fileInfoPanel); // buttons JPanel buttonPannel = new JPanel(); buttonPannel.setAlignmentX(Component.LEFT_ALIGNMENT); buttonPannel.setLayout(new FlowLayout(FlowLayout.TRAILING)); // cancel JButton cancelButton = new JButton(swingConfig.getLocalizer().localize("button.cancel")); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { SettingsDialog.this.dispose(); } }); buttonPannel.add(cancelButton); // save JButton saveButton = new JButton(swingConfig.getLocalizer().localize("button.save")); saveButton.addActionListener(new SaveButtonListener()); buttonPannel.add(saveButton); this.getRootPane().setDefaultButton(saveButton); this.add(basePanel); this.add(buttonPannel); placeOnScreen(swingConfig.getScreenCenter()); }
From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java
/** * Helper factory method for creating a language selector that provides functionality to change the locale. * * @param width/*from w w w. j a v a2 s .co m*/ * the preferred width of the component in pixels * @return the newly created language selector */ protected JComboBox createLanguageSelector(int width) { Preconditions.checkArgument(width >= 0); final JComboBox<SupportedLocale> selector = new JComboBox(i18n.getSupportedLocales().toArray()); selector.setSelectedItem(i18n.getCurrentSupportedLocale()); selector.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { i18n.setLocale((SupportedLocale) selector.getSelectedItem()); } }); int height = selector.getPreferredSize().height; selector.setMinimumSize(new Dimension(width, height)); selector.setMaximumSize(new Dimension(width, height)); selector.setPreferredSize(new Dimension(width, height)); selector.setMaximumRowCount(i18n.getSupportedLocales().size()); selector.setComponentOrientation(ComponentOrientation.getOrientation(i18n.getLocale())); return selector; }
From source file:ffx.ui.ModelingPanel.java
private void initCommandComboBox(JComboBox commands) { commands.setActionCommand("FFXCommand"); commands.setMaximumSize(xyzCommands.getPreferredSize()); commands.setEditable(false);//from w w w .ja va2s . co m commands.setToolTipText("Select a Modeling Command"); commands.setSelectedIndex(0); commands.addActionListener(this); }
From source file:org.ut.biolab.medsavant.client.filter.TagFilterView.java
public TagFilterView(int queryID) { super(FILTER_NAME, queryID); setLayout(new BorderLayout()); setBorder(ViewUtil.getBigBorder());// w w w. j a v a 2 s. c o m setMaximumSize(new Dimension(200, 80)); JPanel cp = new JPanel(); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; cp.setLayout(gbl); variantTags = new ArrayList<VariantTag>(); appliedTags = new ArrayList<VariantTag>(); clear = new JButton("Clear"); applyButton = new JButton("Apply"); try { final JComboBox tagNameCB = new JComboBox(); //tagNameCB.setMaximumSize(new Dimension(1000,30)); final JComboBox tagValueCB = new JComboBox(); //tagValueCB.setMaximumSize(new Dimension(1000,30)); JPanel bottomContainer = new JPanel(); ViewUtil.applyHorizontalBoxLayout(bottomContainer); List<String> tagNames = MedSavantClient.VariantManager .getDistinctTagNames(LoginController.getSessionID()); for (String tag : tagNames) { tagNameCB.addItem(tag); } ta = new JTextArea(); ta.setRows(10); ta.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); ta.setEditable(false); applyButton.setEnabled(false); JLabel addButton = ViewUtil .createIconButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.ADD)); addButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (tagNameCB.getSelectedItem() == null || tagValueCB.getSelectedItem() == null) { return; } VariantTag tag = new VariantTag((String) tagNameCB.getSelectedItem(), (String) tagValueCB.getSelectedItem()); if (variantTags.isEmpty()) { ta.append(tag.toString() + "\n"); } else { ta.append("AND " + tag.toString() + "\n"); } variantTags.add(tag); applyButton.setEnabled(true); } }); clear.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { variantTags.clear(); ta.setText(""); applyButton.setEnabled(true); } }); int width = 150; ta.setPreferredSize(new Dimension(width, width)); ta.setMaximumSize(new Dimension(width, width)); tagNameCB.setPreferredSize(new Dimension(width, 25)); tagValueCB.setPreferredSize(new Dimension(width, 25)); tagNameCB.setMaximumSize(new Dimension(width, 25)); tagValueCB.setMaximumSize(new Dimension(width, 25)); cp.add(new JLabel("Name"), c); c.gridx++; cp.add(tagNameCB, c); c.gridx++; c.gridx = 0; c.gridy++; cp.add(new JLabel("Value"), c); c.gridx++; cp.add(tagValueCB, c); c.gridx++; cp.add(addButton, c); tagNameCB.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent ie) { updateTagValues((String) tagNameCB.getSelectedItem(), tagValueCB); } }); if (tagNameCB.getItemCount() > 0) { tagNameCB.setSelectedIndex(0); updateTagValues((String) tagNameCB.getSelectedItem(), tagValueCB); } al = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { applyButton.setEnabled(false); appliedTags = new ArrayList<VariantTag>(variantTags); Filter f = new Filter() { @Override public Condition[] getConditions() { try { List<Integer> uploadIDs = MedSavantClient.VariantManager .getUploadIDsMatchingVariantTags(LoginController.getSessionID(), TagFilterView.tagsToStringArray(variantTags)); Condition[] uploadIDConditions = new Condition[uploadIDs.size()]; TableSchema table = MedSavantClient.CustomTablesManager.getCustomTableSchema( LoginController.getSessionID(), MedSavantClient.ProjectManager.getVariantTableName( LoginController.getSessionID(), ProjectController.getInstance().getCurrentProjectID(), ReferenceController.getInstance().getCurrentReferenceID(), true)); for (int i = 0; i < uploadIDs.size(); i++) { uploadIDConditions[i] = BinaryCondition.equalTo( table.getDBColumn(BasicVariantColumns.UPLOAD_ID), uploadIDs.get(i)); } return new Condition[] { ComboCondition.or(uploadIDConditions) }; } catch (Exception ex) { ClientMiscUtils.reportError("Error getting upload IDs: %s", ex); } return new Condition[0]; } @Override public String getName() { return FILTER_NAME; } @Override public String getID() { return FILTER_ID; } }; FilterController.getInstance().addFilter(f, TagFilterView.this.queryID); } }; applyButton.addActionListener(al); bottomContainer.add(Box.createHorizontalGlue()); bottomContainer.add(clear); bottomContainer.add(applyButton); add(ViewUtil.getClearBorderedScrollPane(ta), BorderLayout.CENTER); add(bottomContainer, BorderLayout.SOUTH); } catch (Exception ex) { ClientMiscUtils.checkSQLException(ex); } add(cp, BorderLayout.NORTH); this.showViewCard(); }