本文整理汇总了Java中javax.swing.plaf.basic.BasicComboBoxRenderer类的典型用法代码示例。如果您正苦于以下问题:Java BasicComboBoxRenderer类的具体用法?Java BasicComboBoxRenderer怎么用?Java BasicComboBoxRenderer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BasicComboBoxRenderer类属于javax.swing.plaf.basic包,在下文中一共展示了BasicComboBoxRenderer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPreferredSize
import javax.swing.plaf.basic.BasicComboBoxRenderer; //导入依赖的package包/类
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);
tb.add(new JButton("Button", icon)); // NOI18N
tb.add(new JToggleButton("Button", icon)); // NOI18N
tb.add(new JTextField("Text")); // NOI18N
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;
}
示例2: createObjectRenderer
import javax.swing.plaf.basic.BasicComboBoxRenderer; //导入依赖的package包/类
private ListCellRenderer createObjectRenderer(
final ReflectionProvider reflectionProvider) {
return new BasicComboBoxRenderer() {
@Override
public Component getListCellRendererComponent(JList list,
Object value, int index, boolean isSelected,
boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index,
isSelected, cellHasFocus);
String text = "";
if (value != null) {
ClassInfo classInfo = reflectionProvider.getClassInfo(value
.getClass());
text = classInfo.getTitle(value);
}
setText(text);
return this;
}
};
}
示例3: createEnumRenderer
import javax.swing.plaf.basic.BasicComboBoxRenderer; //导入依赖的package包/类
private ListCellRenderer createEnumRenderer(final Format format) {
return new BasicComboBoxRenderer() {
@Override
public Component getListCellRendererComponent(JList list,
Object value, int index, boolean isSelected,
boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index,
isSelected, cellHasFocus);
String text = format.format(value);
setText(text);
return this;
}
};
}
示例4: testGetMinimumSize
import javax.swing.plaf.basic.BasicComboBoxRenderer; //导入依赖的package包/类
public void testGetMinimumSize() throws Exception {
ui.setComboBox(comboBox);
ComboPopup popup = new BasicComboPopup(comboBox);
ui.setPopup(popup);
ui.setListBox(popup.getList());
ui.installListeners();
comboBox.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
Dimension listPart = new BasicComboBoxRenderer().getListCellRendererComponent(
popup.getList(), "", -1, false, false).getPreferredSize();
Dimension expectedSize = new Dimension(listPart.width + listPart.height + 8,
listPart.height + 8);
assertEquals(expectedSize, ui.getMinimumSize(null));
assertEquals(expectedSize, ui.getCachedMinimumSize());
ui.setCachedMinimumSize(new Dimension(100, 100));
assertEquals(ui.getCachedMinimumSize(), ui.getMinimumSize(null));
comboBox.addItem("aaa");
listPart = new BasicComboBoxRenderer().getListCellRendererComponent(popup.getList(),
"aaa", -1, false, false).getPreferredSize();
expectedSize = new Dimension(listPart.width + listPart.height + 8, listPart.height + 8);
assertEquals(expectedSize, ui.getMinimumSize(null));
}
示例5: createRenderer
import javax.swing.plaf.basic.BasicComboBoxRenderer; //导入依赖的package包/类
@Override
protected ListCellRenderer createRenderer() {
return new BasicComboBoxRenderer.UIResource() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
final Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JComponent) {
final JComponent jc = (JComponent)c;
if (index == -1) {
jc.setOpaque(false);
jc.setForeground(list.getForeground());
} else {
jc.setOpaque(true);
}
}
return c;
}
};
}
示例6: PartialDisableComboBox
import javax.swing.plaf.basic.BasicComboBoxRenderer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public PartialDisableComboBox(Object[] items) {
super();
for (Object o : items) {
addItem(o);
}
this.setRenderer(new BasicComboBoxRenderer() {
private static final long serialVersionUID = -2774241371293899669L;
@SuppressWarnings("rawtypes")
@Override
public Component getListCellRendererComponent(JList list, Object value, int index,
boolean isSelected, boolean cellHasFocus) {
Component c =
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
boolean disabled = index >= 0 && index < itemsState.size() && !itemsState.get(index);
c.setEnabled(!disabled);
c.setFocusable(!disabled);
return c;
}
});
}
示例7: createRenderer
import javax.swing.plaf.basic.BasicComboBoxRenderer; //导入依赖的package包/类
@Override
protected ListCellRenderer createRenderer() {
return new BasicComboBoxRenderer.UIResource() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
final Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JComponent) {
final JComponent jc = (JComponent)c;
if (index == -1) {
jc.setOpaque(false);
jc.setForeground(list.getForeground());
}
else {
jc.setOpaque(true);
}
}
return c;
}
};
}
示例8: main
import javax.swing.plaf.basic.BasicComboBoxRenderer; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
invokeAndWait(new Runnable() {
@Override
public void run() {
Integer[] items = {null, 1, 2, 3};
JComboBox<Integer> combo = new JComboBox<>(items);
JLabel label = new JLabel("choose:");
JPanel panel = new JPanel();
GroupLayout layout = new GroupLayout(panel);
panel.setLayout(layout);
label.setLabelFor(combo);
combo.setSelectedIndex(0);
combo.setRenderer(new ListCellRenderer<Integer>() {
private final BasicComboBoxRenderer renderer = new BasicComboBoxRenderer();
@Override
public Component getListCellRendererComponent(JList<? extends Integer> list, Integer value, int index, boolean isSelected, boolean cellHasFocus) {
return this.renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
layout.setAutoCreateContainerGaps(true);
layout.setAutoCreateGaps(true);
layout.setHorizontalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup().addComponent(label))
.addGroup(layout.createParallelGroup().addComponent(combo)));
layout.setVerticalGroup(layout
.createSequentialGroup()
.addGroup(layout
.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(label)
.addComponent(combo)));
JFrame frame = new JFrame(getClass().getSimpleName());
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
});
}
示例9: ComboBoxTableCellEditor
import javax.swing.plaf.basic.BasicComboBoxRenderer; //导入依赖的package包/类
private ComboBoxTableCellEditor() {
myComboBox.setRenderer(new BasicComboBoxRenderer());
myComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stopCellEditing();
}
});
myPanel.add(myComboBox,
new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0,
0));
}
示例10: createRenderer
import javax.swing.plaf.basic.BasicComboBoxRenderer; //导入依赖的package包/类
protected ListCellRenderer createRenderer()
/* 105: */ {
/* 106:186 */ if (this.tableCellEditor) {
/* 107:187 */ return super.createRenderer();
/* 108: */ }
/* 109:189 */ BasicComboBoxRenderer renderer = new BasicComboBoxRenderer.UIResource();
/* 110:190 */ renderer.setBorder(UIManager.getBorder("ComboBox.rendererBorder"));
/* 111:191 */ return renderer;
/* 112: */ }
示例11: ComboBoxTableCellEditor
import javax.swing.plaf.basic.BasicComboBoxRenderer; //导入依赖的package包/类
private ComboBoxTableCellEditor() {
myComboBox.setRenderer(new BasicComboBoxRenderer());
myComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
stopCellEditing();
}
});
myPanel.add(myComboBox,
new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0,
0));
}
示例12: shouldDisplayNoSelected
import javax.swing.plaf.basic.BasicComboBoxRenderer; //导入依赖的package包/类
@Test
public void shouldDisplayNoSelected() {
window.label(new GenericTypeMatcher<BasicComboBoxRenderer>(BasicComboBoxRenderer.class) {
@Override
protected boolean isMatching(BasicComboBoxRenderer component) {
return true;
}
}).requireText(NO_DATA_SOURCE);
}
示例13: createRenderer
import javax.swing.plaf.basic.BasicComboBoxRenderer; //导入依赖的package包/类
protected ListCellRenderer createRenderer()
{
return new BasicComboBoxRenderer();
}
示例14: askUserForProjection
import javax.swing.plaf.basic.BasicComboBoxRenderer; //导入依赖的package包/类
private Projection askUserForProjection() {
Projection proj = null;
// construct list with projection names
java.util.List projNames = ProjectionsManager.getProjectionNames(false, false, false);
DisplayModel dm = projectionBrewerPanel.getModel().getDisplayModel();
if (dm.showFlexProjection) {
Projection flexProj = projectionBrewerPanel.getModel().getDesignProjection();
projNames.add(new JSeparator());
projNames.add(flexProj.getName());
}
// display dialog
JComboBox jcb = new JComboBox(projNames.toArray());
jcb.setMaximumRowCount(projNames.size());
// custom renderer for separator in menu
jcb.setRenderer(new BasicComboBoxRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof JSeparator) {
return (JSeparator) value;
}
return this;
}
});
int res = JOptionPane.showOptionDialog(this, jcb, "Select a Projection",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
null, null, null);
if (res == JOptionPane.OK_OPTION) {
if (jcb.getSelectedIndex() == projNames.size() - 1) {
proj = projectionBrewerPanel.getModel().getDesignProjection();
proj = cloneAndNormalizeIfFlexProjection(proj);
} else {
proj = ProjectionsManager.getProjection((String) (jcb.getSelectedItem()));
}
proj.initialize();
}
return proj;
}
示例15: OneTimePanel
import javax.swing.plaf.basic.BasicComboBoxRenderer; //导入依赖的package包/类
/**
* Create the panel.
*/
public OneTimePanel() {
setLayout(new MigLayout("insets 0", "[120!,left][200:200:]16[:300:]", "[][75px][][]"));
JLabel lblOperation = new JLabel("Operation");
lblOperation.setName("lblOperation");
add(lblOperation, "cell 0 0");
cboOperation = new JComboBox();
cboOperation.setRenderer(new OperationComboRendererDecorator((BasicComboBoxRenderer) cboOperation.getRenderer()));
lblOperation.setLabelFor(cboOperation);
add(cboOperation, "cell 1 0,growx");
JLabel lblImage = new JLabel();
lblImage.setLayout(new BorderLayout(0, 0));
lblImage.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
lblImage.setIcon(new ImageIcon(Thread.currentThread().getContextClassLoader()
.getResource("com/mgmtp/perfload/loadprofiles/ui/onetime.png")));
add(lblImage, "cell 2 0 1 4, alignx right, grow");
JLabel lblTarget = new JLabel("Targets");
lblTarget.setName("lblTarget");
add(lblTarget, "cell 0 1");
JScrollPane scrollPane = new JScrollPane();
scrollPane.setName("scrollPane");
add(scrollPane, "cell 1 1,growx");
{
tblTarget = new JCheckListTable();
scrollPane.setViewportView(tblTarget);
}
lblTarget.setLabelFor(tblTarget);
JLabel lblT0 = new JLabel("<html>T<sub>0</sub> (min)");
add(lblT0, "cell 0 2");
txtT0 = createTextField();
lblT0.setLabelFor(txtT0);
add(txtT0, "cell 1 2, width 50!");
}