use of javax.swing.plaf.basic.BasicComboBoxRenderer in project visualvm by oracle.
the class GenericToolbar method getPreferredSize.
public Dimension getPreferredSize() {
Dimension dim = super.getPreferredSize();
if (PREFERRED_HEIGHT == -1) {
GenericToolbar tb = new GenericToolbar();
tb.setBorder(getBorder());
tb.setBorderPainted(isBorderPainted());
tb.setRollover(isRollover());
tb.setFloatable(isFloatable());
Icon icon = Icons.getIcon(GeneralIcons.SAVE);
// NOI18N
tb.add(new JButton("Button", icon));
// NOI18N
tb.add(new JToggleButton("Button", icon));
// NOI18N
tb.add(new JTextField("Text"));
JComboBox c = new JComboBox();
c.setEditor(new BasicComboBoxEditor());
c.setRenderer(new BasicComboBoxRenderer());
tb.add(c);
tb.addSeparator();
PREFERRED_HEIGHT = tb.getSuperPreferredSize().height;
}
dim.height = getParent() instanceof JToolBar ? 1 : Math.max(dim.height, PREFERRED_HEIGHT);
return dim;
}
use of javax.swing.plaf.basic.BasicComboBoxRenderer in project droid by digital-preservation.
the class FilterDialog method getRowForTable.
/**
* @return Object[] Object Array for the entire row in the filter table.
*/
public Object[] getRowForTable() {
Component component = new TextBoxAndButton(this);
component.hide();
// get all the meta data and load the combo
metaDataCombobox = new JComboBox(filterDomain.getMetaDataNames());
metaDataCombobox.setRenderer(new BasicComboBoxRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
final String displayText = value == null ? "<Please select...>" : value.toString();
return super.getListCellRendererComponent(list, displayText, index, isSelected, cellHasFocus);
}
});
operationCombobox = new JComboBox();
operationComboboxModel = new DefaultComboBoxModel();
operationCombobox.setModel(operationComboboxModel);
metaDataCombobox.addItemListener(new MetaDataComboItemListner());
operationCombobox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED && !filterPredicatesLoading) {
// set the corresponding value at filter context.
FilterCriterionImpl filterCriterion = filterContext.getFilterCriterion(filterTable.getSelectedRow());
JComboBox sourceCombo = (JComboBox) e.getSource();
filterCriterion.setOperator((CriterionOperator) sourceCombo.getSelectedItem());
}
}
});
// Remove button and its listner.
JButton jButton2 = new JButton(REMOVE);
// CHECKSTYLE:OFF FIXME - inner class is too long
jButton2.addActionListener(new ActionListener() {
// CHECKSTYLE:ON
@Override
public void actionPerformed(ActionEvent e) {
if (tableModel.getRowCount() > 1 && (filterTable.getSelectedRow() + 1) != tableModel.getRowCount()) {
int size = filterContext.getNumberOfFilterCriterion();
filterContext.removeFilterCriterion(filterTable.getSelectedRow());
// fill the empty criteria which is been removed.
for (int k = filterTable.getSelectedRow() + 1; k < size; k++) {
filterContext.getFilterCriteriaMap().put(k - 1, filterContext.getFilterCriteriaMap().get(k));
}
// remove the last one
filterContext.removeFilterCriterion(size - 1);
tableModel.removeRow(filterTable.getSelectedRow());
tableModel.fireTableRowsDeleted(filterTable.getSelectedRow(), filterTable.getSelectedRow());
filterTable.revalidate();
initColumnSizes(filterTable);
}
}
});
Object[] data = { metaDataCombobox, operationCombobox, component, jButton2 };
metaDataCombobox.setMaximumRowCount(filterDomain.getMetaDataNames().length);
return data;
}
use of javax.swing.plaf.basic.BasicComboBoxRenderer in project mucommander by mucommander.
the class AppearancePanel method createLookAndFeelPanel.
/**
* Creates the look and feel panel.
*
* @return the look and feel panel.
*/
private JPanel createLookAndFeelPanel() {
JPanel lnfPanel;
// Creates the panel.
lnfPanel = new YBoxPanel();
lnfPanel.setAlignmentX(LEFT_ALIGNMENT);
lnfPanel.setBorder(BorderFactory.createTitledBorder(Translator.get("prefs_dialog.look_and_feel")));
// Creates the look and feel combo box.
lookAndFeelComboBox = new PrefComboBox() {
public boolean hasChanged() {
int selectedIndex = getSelectedIndex();
if (selectedIndex < 0)
return false;
return !lookAndFeels[selectedIndex].getClassName().equals(MuConfigurations.getPreferences().getVariable(MuPreference.LOOK_AND_FEEL));
}
};
lookAndFeelComboBox.setRenderer(new BasicComboBoxRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
JLabel label;
label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (index < 0)
return label;
// All look and feels that are not modifiable must be flagged with a lock icon.
if (isLookAndFeelModifiable(lookAndFeels[index]))
label.setIcon(transparentIcon);
else
label.setIcon(lockIcon);
return label;
}
});
// Populates the look and feel combo box.
populateLookAndFeels();
// Initialises buttons and event listening.
importLookAndFeelButton = new JButton(Translator.get("prefs_dialog.import") + "...");
deleteLookAndFeelButton = new JButton(Translator.get("delete"));
importLookAndFeelButton.addActionListener(this);
deleteLookAndFeelButton.addActionListener(this);
resetLookAndFeelButtons();
lookAndFeelComboBox.addActionListener(this);
// Adds the look and feel list and the action buttons to the panel.
JPanel flowPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
flowPanel.add(lookAndFeelComboBox);
flowPanel.add(importLookAndFeelButton);
flowPanel.add(deleteLookAndFeelButton);
flowPanel.add(new JLabel(dial = new SpinningDial()));
lnfPanel.add(flowPanel);
return lnfPanel;
}
use of javax.swing.plaf.basic.BasicComboBoxRenderer in project jtharness by openjdk.
the class MessageStrip method createRightPanel.
private JComponent createRightPanel() {
JPanel right = uif.createPanel("strip.right", new GridBagLayout(), false);
selector = uif.createLiteralChoice("strip.sel", monitors);
uif.setAccessibleName(selector, "strip.sel");
selector.addActionListener(actionListener);
selector.setRenderer(new BasicComboBoxRenderer() {
@Override
@SuppressWarnings("rawtypes")
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
try {
JLabel lab = (JLabel) c;
if (value instanceof Monitor) {
lab.setText(((Monitor) value).getSmallMonitorName());
}
} catch (ClassCastException e) {
}
return c;
}
});
ContextHelpManager.setHelpIDString(selector, "run.testProgress");
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 2.0d;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.WEST;
monitorCards = new CardLayout();
rightPanel = uif.createPanel("strip.", monitorCards, false);
for (Monitor monitor : monitors) {
rightPanel.add(monitor.getSmallMonitorName(), monitor.getSmallMonitor());
}
currMonitor = getDefaultSmallMonitor();
monitorCards.show(rightPanel, monitors[currMonitor].getSmallMonitorName());
JPanel tmpPanel = uif.createPanel("monitor container", new BorderLayout(), false);
tmpPanel.add(selector, BorderLayout.WEST);
tmpPanel.add(rightPanel, BorderLayout.CENTER);
right.add(tmpPanel, gbc);
gbc.gridx = 1;
gbc.weightx = 0.0d;
/*
gbc.anchor = GridBagConstraints.EAST;
selectButt = uif.createIconButton("strip.drop");
selectButt.addMouseListener(popupListener);
selectButt.addActionListener(popupListener);
uif.setAccessibleName(selectButt, "strip.drop");
gbc.gridx = 2;
*/
magButt = uif.createIconButton("strip.magnify");
magButt.addActionListener(actionListener);
uif.setAccessibleName(magButt, "strip.magnify");
JToolBar tb = uif.createToolBar("strip.tb", magButt);
tb.setFloatable(false);
tb.setBorderPainted(true);
right.add(tb, gbc);
right.setEnabled(true);
right.setVisible(true);
rightPanel.setEnabled(true);
rightPanel.setVisible(true);
return right;
}
use of javax.swing.plaf.basic.BasicComboBoxRenderer in project visualvm by oracle.
the class TransparentToolBar method getPreferredSize.
public Dimension getPreferredSize() {
Dimension dim = getPreferredSizeSuper();
if (horizontal) {
if (PREFERRED_HEIGHT == -1) {
TransparentToolBar tb = new TransparentToolBar();
Icon icon = new Icon() {
public int getIconWidth() {
return 16;
}
public int getIconHeight() {
return 16;
}
public void paintIcon(Component c, Graphics g, int x, int y) {
}
};
// NOI18N
JButton b = new JButton("Button", icon);
tb.addItem(b);
// NOI18N
JToggleButton t = new JToggleButton("Button", icon);
tb.addItem(t);
JComboBox c = new JComboBox();
c.setEditor(new BasicComboBoxEditor());
c.setRenderer(new BasicComboBoxRenderer());
tb.addItem(c);
tb.addSeparator();
PREFERRED_HEIGHT = tb.getPreferredSizeSuper().height;
}
dim.height = Math.max(dim.height, PREFERRED_HEIGHT);
}
return dim;
}
Aggregations