Java Code Examples for javax.swing.JComboBox#setRenderer()

The following examples show how to use javax.swing.JComboBox#setRenderer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CharacterDialog.java    From WorldGrower with GNU General Public License v3.0 6 votes vote down vote up
private JComboBox<ComboBoxEquipmentItem> createEquipmentComboBox(WorldObjectContainer inventory, UnCheckedProperty<WorldObject> propertyKey, ImageInfoReader imageInfoReader) {
	List<WorldObject> worldObjects = getEquipmentItems(inventory, propertyKey);
	List<ComboBoxEquipmentItem> equipmentWorldObjects = new ArrayList<>();
	ComboBoxEquipmentItem noSelectedComboBoxEquipmentItem = new ComboBoxEquipmentItem(null, "");
	equipmentWorldObjects.add(noSelectedComboBoxEquipmentItem);
	ComboBoxEquipmentItem selectedItem = noSelectedComboBoxEquipmentItem;
	for(WorldObject worldObject : worldObjects) {
		ComboBoxEquipmentItem comboBoxEquipmentItem = new ComboBoxEquipmentItem(worldObject, worldObject.getProperty(Constants.NAME));
		if (worldObject == playerCharacter.getProperty(propertyKey)) {
			selectedItem = comboBoxEquipmentItem;
		}
		equipmentWorldObjects.add(comboBoxEquipmentItem);
	}
	
	JComboBox<ComboBoxEquipmentItem> equipmentComboBox = JComboBoxFactory.createJComboBox(equipmentWorldObjects.toArray(new ComboBoxEquipmentItem[0]), imageInfoReader);
	equipmentComboBox.setRenderer(new ComboBoxRenderer(imageInfoReader));
	equipmentComboBox.setSelectedItem(selectedItem);
	equipmentComboBox.addActionListener(new EquipmentChangedAction());
	return equipmentComboBox;
}
 
Example 2
Source File: RepositoryOpenDialog.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void init() {
  locationCombo = new JComboBox();
  locationCombo.setRenderer( new FileObjectRenderer() );
  locationCombo.addActionListener( new SelectLocationAction() );

  fileNameTextField = new JTextField();
  fileNameTextField.getDocument().addDocumentListener( new FileNameValidator() );

  table = new RepositoryTable();
  table.setFilters( REPORT_FILTER );
  table.addKeyListener( new TableInputHandler() );
  table.addMouseListener( new TableInputHandler() );
  table.getSelectionModel().addListSelectionListener( new TableInputHandler() );

  super.init();
}
 
Example 3
Source File: QueryParserPaneProvider.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void setRangeSearchableFields(Collection<String> rangeSearchableFields) {
  pointRangeQueryTable.setModel(new PointTypesTableModel(rangeSearchableFields));
  pointRangeQueryTable.setShowGrid(true);
  String[] numTypes = Arrays.stream(PointTypesTableModel.NumType.values())
      .map(PointTypesTableModel.NumType::name)
      .toArray(String[]::new);
  JComboBox<String> numTypesCombo = new JComboBox<>(numTypes);
  numTypesCombo.setRenderer((list, value, index, isSelected, cellHasFocus) -> new JLabel(value));
  pointRangeQueryTable.getColumnModel().getColumn(PointTypesTableModel.Column.TYPE.getIndex()).setCellEditor(new DefaultCellEditor(numTypesCombo));
  pointRangeQueryTable.getColumnModel().getColumn(PointTypesTableModel.Column.TYPE.getIndex()).setCellRenderer(
      (table, value, isSelected, hasFocus, row, column) -> new JLabel((String) value)
  );
  pointRangeQueryTable.getColumnModel().getColumn(PointTypesTableModel.Column.FIELD.getIndex()).setPreferredWidth(PointTypesTableModel.Column.FIELD.getColumnWidth());
  pointRangeQueryTable.setPreferredScrollableViewportSize(pointRangeQueryTable.getPreferredSize());

  // set default type to Integer
  for (int i = 0; i < rangeSearchableFields.size(); i++) {
    pointRangeQueryTable.setValueAt(PointTypesTableModel.NumType.INT.name(), i, PointTypesTableModel.Column.TYPE.getIndex());
  }

}
 
Example 4
Source File: RoiMaskSelector.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public RoiMaskSelector(BindingContext bindingContext) {
    final Property useRoiMaskProperty = bindingContext.getPropertySet().getProperty(PROPERTY_NAME_USE_ROI_MASK);
    Assert.argument(useRoiMaskProperty != null, "bindingContext");
    Assert.argument(useRoiMaskProperty.getType().equals(Boolean.class) || useRoiMaskProperty.getType() == Boolean.TYPE, "bindingContext");
    Assert.argument(bindingContext.getPropertySet().getProperty(PROPERTY_NAME_ROI_MASK) != null, "bindingContext");
    Assert.argument(bindingContext.getPropertySet().getProperty(PROPERTY_NAME_ROI_MASK).getType().equals(Mask.class), "bindingContext");

    this.productNodeListener = new PNL();
    this.bindingContext = bindingContext;
    useRoiMaskCheckBox = new JCheckBox("Use ROI mask:");
    roiMaskComboBox = new JComboBox();
    roiMaskComboBox.setRenderer(new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value != null) {
                this.setText(((Mask) value).getName());
            }
            return this;
        }
    });

    this.showMaskManagerButton = createShowMaskManagerButton();

    bindingContext.bind(PROPERTY_NAME_USE_ROI_MASK, useRoiMaskCheckBox);
    bindingContext.bind(PROPERTY_NAME_ROI_MASK, roiMaskComboBox);

    bindingContext.bindEnabledState(PROPERTY_NAME_USE_ROI_MASK, true, createUseRoiCondition());
    bindingContext.bindEnabledState(PROPERTY_NAME_ROI_MASK, true, createEnableMaskDropDownCondition());
}
 
Example 5
Source File: ProjectAssociationAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Messages({
    "ProjectAssociationAction.open_some_projects=Open some projects to choose from.",
    "ProjectAssociationAction.title_select_project=Select Project",
    "ProjectAssociationAction.could_not_associate=Failed to record a Hudson job association.",
    "ProjectAssociationAction.could_not_dissociate=Failed to find the Hudson job association to be removed."
})
@Override public void actionPerformed(ActionEvent e) {
    if (alreadyAssociatedProject == null) {
        SortedSet<Project> projects = new TreeSet<Project>(ProjectRenderer.comparator());
        projects.addAll(Arrays.asList(OpenProjects.getDefault().getOpenProjects()));
        if (projects.isEmpty()) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(Bundle.ProjectAssociationAction_open_some_projects(), NotifyDescriptor.INFORMATION_MESSAGE));
            return;
        }
        JComboBox box = new JComboBox(new DefaultComboBoxModel(projects.toArray(new Project[projects.size()])));
        box.setRenderer(new ProjectRenderer());
        if (DialogDisplayer.getDefault().notify(new NotifyDescriptor(box, Bundle.ProjectAssociationAction_title_select_project(), NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.PLAIN_MESSAGE, null, null)) != NotifyDescriptor.OK_OPTION) {
            return;
        }
        if (!ProjectHudsonProvider.getDefault().recordAssociation((Project) box.getSelectedItem(), assoc)) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(Bundle.ProjectAssociationAction_could_not_associate(), NotifyDescriptor.WARNING_MESSAGE));
        }
    } else {
        if (!ProjectHudsonProvider.getDefault().recordAssociation(alreadyAssociatedProject, null)) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(Bundle.ProjectAssociationAction_could_not_dissociate(), NotifyDescriptor.WARNING_MESSAGE));
        }
    }
}
 
Example 6
Source File: ConfirmDeclarationDialog.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
private <T> void addComboBox(JPanel panel, JComboBox<T> box,
                             String prefix, T value) {
    box.setRenderer(new EnumRenderer<T>(prefix));
    box.setSelectedItem(value);
    box.addItemListener(this);
    panel.add(Utility.localizedLabel(prefix + "label"));
    panel.add(box);
}
 
Example 7
Source File: ExportDialog.java    From FCMFrame with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of ExportDialog.
 * 
 * @param creator
 *            The "creator" to be written into the header of the file (may
 *            be null)
 * @param addAllExportFileTypes
 *            If true registers all the standard export filetypes
 */
public ExportDialog(String creator, boolean addAllExportFileTypes) {
	super(null, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
	this.creator = creator;

	try {
		baseDir = System.getProperty("user.home");
	} catch (SecurityException x) {
		trusted = false;
	}

	ButtonListener bl = new ButtonListener();

	JPanel panel = new JPanel(new TableLayout());

	if (trusted) {
		panel.add("* * [5 5 5 5] w", file);
		panel.add("* * * 1 [5 5 5 5] wh", browse);
	}
	type = new JComboBox(list);
	type.setMaximumRowCount(16); // rather than 8
	panel.add("* * 1 1 [5 5 5 5] w", type);

	panel.add("* * * 1 [5 5 5 5] wh", advanced);

	browse.addActionListener(bl);
	advanced.addActionListener(bl);
	type.setRenderer(new SaveAsRenderer());
	type.addActionListener(bl);

	setMessage(panel);

	if (addAllExportFileTypes)
		addAllExportFileTypes();
}
 
Example 8
Source File: ImportChooserInnerPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JComboBox createComboBox( String[] choices, String defaultValue, Icon[] icons, Font font, FocusListener listener ) {
    JComboBox combo = new JComboBox(choices);
    combo.setSelectedItem(defaultValue);
    combo.getAccessibleContext().setAccessibleDescription(getBundleString("FixDupImportStmts_Combo_ACSD")); //NOI18N
    combo.getAccessibleContext().setAccessibleName(getBundleString("FixDupImportStmts_Combo_Name_ACSD")); //NOI18N
    combo.setOpaque(false);
    combo.setFont( font );
    combo.addFocusListener( listener );
    combo.setEnabled( choices.length > 1 );
    combo.setRenderer( new DelegatingRenderer(combo.getRenderer(), choices, icons ) );
    InputMap inputMap = combo.getInputMap( JComboBox.WHEN_FOCUSED );
    inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_SPACE, 0), "showPopup" ); //NOI18N
    combo.getActionMap().put( "showPopup", new TogglePopupAction() ); //NOI18N
    return combo;
}
 
Example 9
Source File: ResourcesCustomizer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static TableCellEditor createEditor() {
    final JComboBox combo = new JComboBox(new Object[] {Boolean.TRUE, Boolean.FALSE});
    combo.setRenderer(new DefaultListCellRenderer(){
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            return super.getListCellRendererComponent(
                    list,
                    NbBundle.getMessage(ResourcesCustomizer.class, value == Boolean.TRUE ? "TXT_LAZY":"TXT_EAGER"),
                    index,
                    isSelected,
                    cellHasFocus);
        }            
    });
    return new DefaultCellEditor(combo);
}
 
Example 10
Source File: FixDuplicateImportStmts.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private JComboBox createComboBox(CandidateDescription[] choices, CandidateDescription defaultValue, Font font, FocusListener listener ) {
    JComboBox combo = new JComboBox(choices);
    combo.setSelectedItem(defaultValue);
    combo.getAccessibleContext().setAccessibleDescription(getBundleString("FixDupImportStmts_Combo_ACSD")); //NOI18N
    combo.getAccessibleContext().setAccessibleName(getBundleString("FixDupImportStmts_Combo_Name_ACSD")); //NOI18N
    combo.setOpaque(false);
    combo.setFont( font );
    combo.addFocusListener( listener );
    combo.setEnabled( choices.length > 1 );
    combo.setRenderer( new DelegatingRenderer(combo.getRenderer()));
    InputMap inputMap = combo.getInputMap( JComboBox.WHEN_FOCUSED );
    inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_SPACE, 0), "showPopup" ); //NOI18N
    combo.getActionMap().put( "showPopup", new TogglePopupAction() ); //NOI18N
    return combo;
}
 
Example 11
Source File: UITools.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public static JComboBox<MagicEdition> createComboboxEditions(List<MagicEdition> value,SIZE s) {
	DefaultComboBoxModel<MagicEdition> model = new DefaultComboBoxModel<>();
	JComboBox<MagicEdition> combo = new JComboBox<>(model);
	value.forEach(model::addElement);
	combo.setRenderer(new MagicEditionIconListRenderer(s));
	return combo;
}
 
Example 12
Source File: PreferencesDialog.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({
                   "unchecked"
} )
protected <T> JPanel mkCombo(final ChoicePref<T> pref) {
    JComboBox cb = make(new JComboBox(mkComboBoxModelFor(pref)));
    pref2comp.put(pref, cb);
    cb.setRenderer(new CBRenderer() {

        @Override
        protected Object render(Object value) {
            return pref.renderValueShort((T) value);
        }
    });
    return OurUtil.makeH(pref.title + ": ", cb);
}
 
Example 13
Source File: Attributes.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public java.awt.Component getCellEditor(Object value) {
	JComboBox<Object> combo = new JComboBox<Object>(vals);
	combo.setRenderer(new OptionComboRenderer<V>(this));
	if (value == null)
		combo.setSelectedIndex(-1);
	else
		combo.setSelectedItem(value);
	return combo;
}
 
Example 14
Source File: SimpleThemeEditor.java    From WorldPainter with GNU General Public License v3.0 5 votes vote down vote up
public void setTheme(SimpleTheme theme) {
    this.theme = theme;
    if (theme != null) {
        terrainTableModel = new TerrainRangesTableModel(theme.getTerrainRanges());
        terrainTableModel.setChangeListener(this);
        tableTerrain.setModel(terrainTableModel);
        
        tableTerrain.setDefaultRenderer(Integer.class, new DefaultTableCellRenderer());
        tableTerrain.setDefaultRenderer(Terrain.class, new TerrainTableCellRenderer(colourScheme));
        tableTerrain.setDefaultRenderer(JButton.class, new JButtonTableCellRenderer());
        
        tableTerrain.setDefaultEditor(Integer.class, new JSpinnerTableCellEditor(new SpinnerNumberModel(1, 1, theme.getMaxHeight() - 1, 1)));
        JComboBox terrainEditor = new JComboBox(Terrain.getConfiguredValues());
        terrainEditor.setRenderer(new TerrainListCellRenderer(colourScheme));
        tableTerrain.setDefaultEditor(Terrain.class, new DefaultCellEditor(terrainEditor));
        tableTerrain.setDefaultEditor(JButton.class, new JButtonTableCellEditor(this));
        
        checkBoxBeaches.setSelected(theme.isBeaches());
        spinnerWaterLevel.setModel(new SpinnerNumberModel(theme.getWaterHeight(), 0, theme.getMaxHeight() - 1, 1));
        spinnerWaterLevel.setEnabled(checkBoxBeaches.isSelected());
        
        checkBoxRandomise.setSelected(theme.isRandomise());
        
        layerTableModel = new LayerRangesTableModel(theme.getMaxHeight(), theme.getLayerMap());
        tableLayers.setModel(layerTableModel);

        tableLayers.setDefaultRenderer(Layer.class, new LayerTableCellRenderer());
        tableLayers.setDefaultRenderer(JButton.class, new JButtonTableCellRenderer());
        
        tableLayers.setDefaultEditor(Integer.class, new JSpinnerTableCellEditor(new SpinnerNumberModel(1, 1, theme.getMaxHeight() - 1, 1)));
        tableLayers.setDefaultEditor(JButton.class, new JButtonTableCellEditor(this));
    }
}
 
Example 15
Source File: LineStyleAttributePlugin.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public TableCellEditor getTableCellEditor(final Engine engine,
                                          final AccessRules rules, final Attribute attribute) {
    final JComboBox box = new JComboBox();
    box.setRenderer(comboBoxRenderer);

    for (Stroke stroke : LineStyleChooser.getStrokes()) {
        box.addItem(stroke);
    }

    return new DefaultCellEditor(box) {
        private Pin pin;

        @Override
        public boolean stopCellEditing() {
            if (box.getSelectedItem() instanceof Stroke) {
                ((Journaled) engine).startUserTransaction();
                apply((BasicStroke) box.getSelectedItem(), pin);
                return super.stopCellEditing();
            }
            return false;
        }

        @Override
        public Component getTableCellEditorComponent(JTable table,
                                                     Object value, boolean isSelected, int row, int column) {
            pin = (Pin) ((MetadataGetter) table).getMetadata();
            return super.getTableCellEditorComponent(table, value,
                    isSelected, row, column);
        }
    };
}
 
Example 16
Source File: GetAllSkins.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates the main frame for <code>this</code> sample.
 */
public GetAllSkins() {
    super("Get all skins");

    setLayout(new BorderLayout());

    final JPanel panel = new JPanel(new FlowLayout());
    // Get all skins and set the vector as a model
    // for combobox.
    final JComboBox<SkinInfo> cb = new JComboBox<>(
            new Vector<>(SubstanceCortex.GlobalScope.getAllSkins().values()));
    cb.setRenderer(new SubstanceDefaultComboBoxRenderer(cb) {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index,
                boolean isSelected, boolean cellHasFocus) {
            SkinInfo si = (SkinInfo) value;
            return super.getListCellRendererComponent(list, si.getDisplayName(), index,
                    isSelected, cellHasFocus);
        }
    });
    panel.add(new JLabel("All skins:"));
    panel.add(cb);

    this.add(panel, BorderLayout.CENTER);

    this.setSize(400, 200);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
 
Example 17
Source File: AddThemeEntry.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initializes a combo box for editing UIID's
 */
public static void initUIIDComboBox(JComboBox jc) {
    jc.setEditable(true);
    Vector uiids = new Vector();
    uiids.add("");
    for(Object k : Accessor.getThemeProps().keySet()) {
        String key = (String)k;
        int dot = key.indexOf('.');
        if(dot > -1 && key.indexOf('@') < 0) {
            key = key.substring(0, dot);
            if(!uiids.contains(key)) {
                uiids.add(key);
            }
        }
    }
    Collections.sort(uiids, String.CASE_INSENSITIVE_ORDER);
    jc.setModel(new DefaultComboBoxModel(uiids));
    com.codename1.ui.Form currentForm = com.codename1.ui.Display.getInstance().getCurrent();
    if(currentForm != null) {
        final List<String> currentFormUIIDs = new ArrayList<String>();
        findAllUIIDs(currentFormUIIDs, currentForm);
        Collections.sort(currentFormUIIDs, String.CASE_INSENSITIVE_ORDER);
        Collections.reverse(currentFormUIIDs);
        for(String cmp : currentFormUIIDs) {
            jc.insertItemAt(cmp, 1);
        }
        jc.setRenderer(new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                String uiid = (String)value;
                if(index > 0 && index < currentFormUIIDs.size() + 1) {
                    value = "<html><body><b>" + value + "</b></body></html>";
                } else {
                    if(value == null || ((String)value).length() == 0) {
                        value = "[null]";
                    }
                }
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                setIcon(ThemeEditor.getUIIDPreviewImage(uiid, false, false, false));
                return this;
            }
        });
    }
}
 
Example 18
Source File: ShapefileAssistantPage1.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Component createPageComponent() {
    GridBagConstraints gbc = new GridBagConstraints();
    final JPanel panel = new JPanel(new GridBagLayout());

    gbc.anchor = GridBagConstraints.WEST;

    gbc.gridy = 0;
    gbc.gridx = 0;
    gbc.gridy++;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridwidth = 2;
    panel.add(new JLabel("Path to ESRI Shapefile (*.shp):"), gbc);

    gbc.weightx = 1;
    gbc.weighty = 0;
    gbc.gridx = 0;
    gbc.gridy++;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.gridwidth = 1;
    final LayerSourcePageContext context = getContext();
    final Preferences preferences = SnapApp.getDefault().getPreferences();
    final FileHistory fileHistory = new FileHistory(5, PROPERTY_LAST_FILE_PREFIX);
    fileHistory.initBy(preferences);
    fileHistoryModel = new HistoryComboBoxModel(fileHistory);
    JComboBox shapefileBox = new JComboBox(fileHistoryModel);
    shapefileBox.setRenderer(new FilePathListCellRenderer(80));
    shapefileBox.setEditable(true);
    shapefileBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            context.updateState();
        }
    });
    panel.add(shapefileBox, gbc);

    gbc.weightx = 0;
    gbc.weighty = 0;
    gbc.gridx = 1;
    gbc.fill = GridBagConstraints.NONE;
    gbc.gridwidth = 1;
    JButton button = new JButton("...");
    button.addActionListener(new ShpaeFilechooserActionListener());
    panel.add(button, gbc);

    return panel;
}
 
Example 19
Source File: SetMenuGutterFillKind.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Creates the main frame for <code>this</code> sample.
 */
public SetMenuGutterFillKind() {
    super("Menu gutter fill kind");

    setLayout(new BorderLayout());

    // create sample menu bar with one menu and a few menu items
    JMenuBar jmb = new JMenuBar();
    JMenu menu = new JMenu("menu");
    menu.add(new JMenuItem("test item 1", mx.of(16, 16)));
    menu.add(new JMenuItem("test item 2"));
    menu.add(new JMenuItem("test item 3"));
    menu.addSeparator();
    menu.add(new JMenuItem("test menu item 4"));
    menu.add(new JMenuItem("test menu item 5", se.of(16, 16)));
    menu.add(new JMenuItem("test menu item 6"));
    jmb.add(menu);

    setJMenuBar(jmb);

    JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));

    final JComboBox<MenuGutterFillKind> menuGutterFillCombo = new JComboBox<>(
            new MenuGutterFillKind[] {
                    MenuGutterFillKind.NONE,
                    MenuGutterFillKind.SOFT,
                    MenuGutterFillKind.HARD,
                    MenuGutterFillKind.SOFT_FILL,
                    MenuGutterFillKind.HARD_FILL});
    menuGutterFillCombo.setRenderer(new SubstanceDefaultComboBoxRenderer(menuGutterFillCombo) {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index,
                boolean isSelected, boolean cellHasFocus) {
            MenuGutterFillKind mgfk = (MenuGutterFillKind) value;
            return super.getListCellRendererComponent(list, mgfk.name().toLowerCase(), index,
                    isSelected, cellHasFocus);
        }
    });
    menuGutterFillCombo.setSelectedItem(MenuGutterFillKind.HARD);
    // based on the selected item, set the global menu gutter fill kind
    menuGutterFillCombo.addActionListener((ActionEvent e) -> SubstanceCortex.GlobalScope
            .setMenuGutterFillKind((MenuGutterFillKind) menuGutterFillCombo.getSelectedItem()));
    controls.add(new JLabel("Menu fill"));
    controls.add(menuGutterFillCombo);

    this.add(controls, BorderLayout.SOUTH);

    this.setSize(400, 200);
    setLocationRelativeTo(null);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
 
Example 20
Source File: ShapefileAssistantPage3.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Component createPageComponent() {
    mapPanel = new JPanel(new BorderLayout());
    mapLabel = new JLabel();
    mapLabel.setHorizontalAlignment(JLabel.CENTER);
    mapPanel.add(mapLabel, BorderLayout.CENTER);

    LayerSourcePageContext context = getContext();
    String filePath = (String) context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FILE_PATH);
    String fileName = new File(filePath).getName();

    infoLabel = new JLabel();

    styleList = new JComboBox();
    styleList.setRenderer(new StyleListCellRenderer());
    styleList.addItemListener(new StyleSelectionListener());
    styleList.setPreferredSize(new Dimension(100, styleList.getPreferredSize().height));

    JPanel panel2 = new JPanel(new BorderLayout(4, 4));
    panel2.setBorder(new EmptyBorder(4, 4, 4, 4));
    panel2.add(new JLabel("Style:"), BorderLayout.WEST);
    panel2.add(styleList, BorderLayout.EAST);

    JPanel panel3 = new JPanel(new BorderLayout(4, 4));
    panel3.setBorder(new EmptyBorder(4, 4, 4, 4));
    panel3.add(new JLabel(String.format("<html><b>%s</b>", fileName)), BorderLayout.CENTER);
    panel3.add(panel2, BorderLayout.EAST);

    JPanel panel = new JPanel(new BorderLayout(4, 4));
    panel.setBorder(new EmptyBorder(4, 4, 4, 4));
    panel.add(panel3, BorderLayout.NORTH);
    panel.add(mapPanel, BorderLayout.CENTER);
    panel.add(infoLabel, BorderLayout.SOUTH);

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            updateMap();
        }
    });
    return panel;
}