本文整理匯總了Java中javax.swing.plaf.basic.BasicComboBoxEditor類的典型用法代碼示例。如果您正苦於以下問題:Java BasicComboBoxEditor類的具體用法?Java BasicComboBoxEditor怎麽用?Java BasicComboBoxEditor使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BasicComboBoxEditor類屬於javax.swing.plaf.basic包,在下文中一共展示了BasicComboBoxEditor類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPreferredSize
import javax.swing.plaf.basic.BasicComboBoxEditor; //導入依賴的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: createTargetOptionsCombo
import javax.swing.plaf.basic.BasicComboBoxEditor; //導入依賴的package包/類
private static ComboBox createTargetOptionsCombo() {
final ComboBox combo = new ComboBox(new TargetLevelComboboxModel());
//combo.setRenderer(new DefaultListCellRenderer() {
// @Override
// public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
// try {
// return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
// }
// finally {
// //if ("".equals(value)) {
// // setText(COMPILER_DEFAULT);
// //}
// }
// }
//});
combo.setEditable(true);
combo.setEditor(new BasicComboBoxEditor() {
@Override
protected JTextField createEditorComponent() {
return new HintTextField(COMPILER_DEFAULT, 12);
}
});
return combo;
}
示例3: CGraphSearchField
import javax.swing.plaf.basic.BasicComboBoxEditor; //導入依賴的package包/類
/**
* Creates a new search field.
*
* @param graph Graph searched through by this field.
*/
public CGraphSearchField(final ZyGraph graph) {
super(20);
Preconditions.checkNotNull(graph, "IE01812: Target view can't be null");
m_graph = graph;
m_searcher = new GraphSearcher();
setEditor(new BasicComboBoxEditor() {
@Override
protected JTextField createEditorComponent() {
return m_textField;
}
});
registerHotkeys();
}
示例4: HistoryField
import javax.swing.plaf.basic.BasicComboBoxEditor; //導入依賴的package包/類
HistoryField(final int maxHistory){
this.maxHistory = maxHistory;
history = new ArrayList<String>(){
@Override
public boolean add(String s) {
if(this.size() >= maxHistory) remove(0);
return super.add(s);
}
};
this.setModel(new HistoryComboModel());
this.setEditor(new BasicComboBoxEditor(){
JTextField editorComponent;
@Override
protected JTextField createEditorComponent() {
editorComponent = new JTextField();
return editorComponent;
}
@Override
public Component getEditorComponent() {
return editorComponent;
}
});
this.setEditable(true);
this.setOpaque(true);
}
示例5: createTargetOptionsCombo
import javax.swing.plaf.basic.BasicComboBoxEditor; //導入依賴的package包/類
private static ComboBox createTargetOptionsCombo() {
final ComboBox combo = new ComboBox(new TargetLevelComboboxModel());
//combo.setRenderer(new DefaultListCellRenderer() {
// @Override
// public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
// try {
// return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
// }
// finally {
// //if ("".equals(value)) {
// // setText(COMPILER_DEFAULT);
// //}
// }
// }
//});
combo.setEditable(true);
combo.setEditor(new BasicComboBoxEditor() {
@Override
protected JTextField createEditorComponent() {
return new HintTextField(COMPILER_DEFAULT, 10);
}
});
return combo;
}
示例6: ForWhatScrnMap
import javax.swing.plaf.basic.BasicComboBoxEditor; //導入依賴的package包/類
public ForWhatScrnMap(final int i, final String[] as,
final DefaultComboBoxModel<String> defaultcomboboxmodel)
{
super(SearchOptionsConstants.FOR_WHAT_FIELD_ID[i],
defaultcomboboxmodel);
setEditable(true);
setEditor(new BasicComboBoxEditor());
setSelectedItem(SearchOptionsConstants.FIELD_ATTR[fieldId].defaultText);
setDefaultToCurrentValue();
setBorder(BorderFactory
.createLineBorder(SearchOptionsConstants.FOR_WHAT_BORDER_COLOR, 3));
((JTextField)getEditor().getEditorComponent())
.addMouseListener(new SearchJTextFieldPopupMenuListener(
new SearchJTextFieldPopupMenu()));
((JTextField)getEditor().getEditorComponent())
.setToolTipText(SearchOptionsConstants.FIELD_ATTR[fieldId].toolTip);
}
示例7: constructPanel
import javax.swing.plaf.basic.BasicComboBoxEditor; //導入依賴的package包/類
private void constructPanel(String[] values) {
// constructing editors
editors = new PropertyValueCellEditor[types.length];
for (int i = 0; i < types.length; i++) {
editors[i] = PropertyPanel.instantiateValueCellEditor(types[i], operator);
}
// building panel
panel = new JPanel();
panel.setFocusable(true);
panel.setLayout(new GridLayout(1, editors.length));
for (int i = 0; i < types.length; i++) {
Component editorComponent = editors[i].getTableCellEditorComponent(null, values[i], false, 0, 0);
if (editorComponent instanceof JComboBox && ((JComboBox) editorComponent).isEditable()) {
if (((JComboBox) editorComponent).isEditable()) {
ComboBoxEditor editor = ((JComboBox) editorComponent).getEditor();
if (editor instanceof BasicComboBoxEditor) {
editor.getEditorComponent().addFocusListener(focusListener);
}
} else {
editorComponent.addFocusListener(focusListener);
}
} else if (editorComponent instanceof JPanel) {
JPanel editorPanel = (JPanel) editorComponent;
Component[] components = editorPanel.getComponents();
for (Component comp : components) {
comp.addFocusListener(focusListener);
}
} else {
editorComponent.addFocusListener(focusListener);
}
panel.add(editorComponent);
panel.addFocusListener(focusListener);
}
}
示例8: testBasicComboBoxEditor
import javax.swing.plaf.basic.BasicComboBoxEditor; //導入依賴的package包/類
private static void testBasicComboBoxEditor() {
BasicComboBoxEditor comboBoxEditor = new BasicComboBoxEditor();
comboBoxEditor.setItem(new UserComboBoxEditorType("100"));
JTextField editor = (JTextField) comboBoxEditor.getEditorComponent();
editor.setText("200");
UserComboBoxEditorType item = (UserComboBoxEditorType) comboBoxEditor.getItem();
if (!item.str.equals("200")) {
throw new RuntimeException("Wrong itme value!");
}
}
示例9: addChoice
import javax.swing.plaf.basic.BasicComboBoxEditor; //導入依賴的package包/類
/** Create a choice menu.
* @param name The name used to identify the entry (when calling get).
* @param label The label to attach to the entry.
* @param values The list of possible choices.
* @param defaultChoice Default choice.
* @param editable True if an arbitrary choice can be entered, in addition
* to the choices in values.
* @param background The background color for the editable part.
* @param foreground The foreground color for the editable part.
*/
public void addChoice(String name, String label, String[] values,
String defaultChoice, boolean editable, final Color background,
final Color foreground) {
JLabel lbl = new JLabel(label + ": ");
lbl.setBackground(_background);
JComboBox combobox = new JComboBox(values);
combobox.setEditable(editable);
// NOTE: Typical of Swing, the following does not set
// the background color. So we have to specify a
// custom editor. #$(#&$#(@#!!
// combobox.setBackground(background);
combobox.setEditor(new BasicComboBoxEditor() {
public Component getEditorComponent() {
Component result = super.getEditorComponent();
result.setBackground(background);
result.setForeground(foreground);
return result;
}
});
combobox.setSelectedItem(defaultChoice);
_addPair(name, lbl, combobox, combobox);
// Add the listener last so that there is no notification
// of the first value.
combobox.addItemListener(new QueryItemListener(name));
}
示例10: constructPanel
import javax.swing.plaf.basic.BasicComboBoxEditor; //導入依賴的package包/類
private void constructPanel(String[] values) {
// constructing editors
editors = new PropertyValueCellEditor[types.length];
for (int i = 0; i < types.length; i++) {
editors[i] = PropertyPanel.instantiateValueCellEditor(types[i], operator);
}
// building panel
panel = new JPanel();
panel.setFocusable(true);
panel.setLayout(new GridLayout(1, editors.length));
for (int i = 0; i < types.length; i++) {
Component editorComponent = editors[i].getTableCellEditorComponent(null, values[i], false, 0, 0);
if (editorComponent instanceof JComboBox) {
if (((JComboBox<?>) editorComponent).isEditable()) {
ComboBoxEditor editor = ((JComboBox<?>) editorComponent).getEditor();
if (editor instanceof BasicComboBoxEditor) {
editor.getEditorComponent().addFocusListener(focusListener);
}
} else {
editorComponent.addFocusListener(focusListener);
}
} else if (editorComponent instanceof JPanel) {
JPanel editorPanel = (JPanel) editorComponent;
Component[] components = editorPanel.getComponents();
for (Component comp : components) {
comp.addFocusListener(focusListener);
}
} else {
editorComponent.addFocusListener(focusListener);
}
panel.add(editorComponent);
panel.addFocusListener(focusListener);
}
}
示例11: CGotoAddressField
import javax.swing.plaf.basic.BasicComboBoxEditor; //導入依賴的package包/類
/**
* Creates a new Goto Address field.
*
* @param graph The graph the address field refers to.
* @param modules The list of modules present in the graph
* @param parent The parent JFrame
*/
public CGotoAddressField(final ZyGraph graph, final List<INaviModule> modules, final JFrame parent) {
super(20);
m_graph = Preconditions.checkNotNull(graph, "IE01811: Graph argument can't be null");
m_modules = Preconditions.checkNotNull(modules, "IE01176: Modules argument can not be null");
m_parent = Preconditions.checkNotNull(parent, "IE02845: parent argument can not be null");
// Code to fix some kind of combo box GUI issue with formatted text fields
m_textField.setPreferredSize(getPreferredSize());
m_textField.setBorder(((JTextField) new JComboBox().getEditor().getEditorComponent())
.getBorder());
setEditor(new BasicComboBoxEditor() {
@Override
protected JTextField createEditorComponent() {
return m_textField;
}
});
((JTextField) getEditor().getEditorComponent()).getInputMap().put(
HotKeys.GRAPH_SEARCH_NEXT_KEY.getKeyStroke(), "ZOOM");
((JTextField) getEditor().getEditorComponent()).getActionMap().put("ZOOM",
new AbstractAction() {
private static final long serialVersionUID = 4721578747969744911L;
@Override
public void actionPerformed(final ActionEvent event) {
if (m_modules.size() == 1) {
zoomToAddress();
} else {
buildAddressSelectionPopUp();
}
}
});
addActionListener(m_listener);
}
示例12: createEditor
import javax.swing.plaf.basic.BasicComboBoxEditor; //導入依賴的package包/類
/**
* Creates the default editor that will be used in editable combo boxes.
* A default editor will be used only if an editor has not been
* explicitly set with <code>setEditor</code>.
*
* @return a <code>ComboBoxEditor</code> used for the combo box
* @see javax.swing.JComboBox#setEditor
*/
protected ComboBoxEditor createEditor()
{
BasicComboBoxEditor.UIResource bcbe = new BasicComboBoxEditor.UIResource();
if(bcbe != null)
{
Component c = bcbe.getEditorComponent();
if(c != null)
{
//把默認的Editor設置成透明(editor不透明的話就會遮住NP背景圖,從而使得外觀難看)
((JComponent)c).setOpaque(false);
//* 以下這段是為了給默認Editor加上border而加(沒有它個border將使
//* 得與不可編輯comboBox的內容組件看起來有差異哦),
//* 在WindowsComboBoxUI中,這段代碼是放在WindowsComboBoxEditor
//* 中的方法createEditorComponent中實現,由於該 方法是1.6裏才有的,
//* BE LNF因要兼容java1.5,所以不作類似實現就在本方法中實現也沒有問題。
//* 類似實現請參考WindowsComboBoxUI.WindowsComboBoxEditor類
// JTextField editor = (JTextField)c;
Border border = (Border)UIManager.get("ComboBox.editorBorder");
if (border != null)
{
((JComponent)c).setBorder(border);
}
}
}
return bcbe;
}
示例13: addChoice
import javax.swing.plaf.basic.BasicComboBoxEditor; //導入依賴的package包/類
/** Create a choice menu.
* @param name The name used to identify the entry (when calling get).
* @param label The label to attach to the entry.
* @param values The list of possible choices.
* @param defaultChoice Default choice.
* @param editable True if an arbitrary choice can be entered, in addition
* to the choices in values.
* @param background The background color for the editable part.
* @param foreground The foreground color for the editable part.
* @return The combo box for the choice.
*/
public JComboBox<Object> addChoice(String name, String label, Object[] values,
Object defaultChoice, boolean editable, final Color background,
final Color foreground) {
JLabel lbl = new JLabel(label + ": ");
lbl.setBackground(_background);
JComboBox<Object> combobox = new JComboBox<Object>(values);
combobox.setEditable(editable);
// NOTE: Typical of Swing, the following does not set
// the background color. So we have to specify a
// custom editor. #$(#&$#(@#!!
// combobox.setBackground(background);
combobox.setEditor(new BasicComboBoxEditor() {
@Override
public Component getEditorComponent() {
Component result = super.getEditorComponent();
result.setBackground(background);
result.setForeground(foreground);
return result;
}
});
combobox.setSelectedItem(defaultChoice);
_addPair(name, lbl, combobox, combobox);
// Add the listener last so that there is no notification
// of the first value.
combobox.addItemListener(new QueryItemListener(this, name));
return combobox;
}
示例14: testGetSetEditor
import javax.swing.plaf.basic.BasicComboBoxEditor; //導入依賴的package包/類
public void testGetSetEditor() throws Exception {
assertNotNull(comboBox.getEditor());
ComboBoxEditor newEditor = new BasicComboBoxEditor();
comboBox.setEditor(newEditor);
assertEquals(newEditor, comboBox.getEditor());
assertTrue(propertyChangeController.isChanged("editor"));
comboBox.setEditor(null);
assertNull(comboBox.getEditor());
}
示例15: constructPanel
import javax.swing.plaf.basic.BasicComboBoxEditor; //導入依賴的package包/類
private void constructPanel(String[] values) {
// constructing editors
editors = new PropertyValueCellEditor[types.length];
for (int i = 0; i < types.length; i++) {
editors[i] = PropertyPanel.instantiateValueCellEditor(types[i], operator);
}
// building panel
panel = new JPanel();
panel.setFocusable(true);
panel.setLayout(new GridLayout(1, editors.length));
for (int i = 0; i < types.length; i++) {
Component editorComponent = editors[i].getTableCellEditorComponent(null, values[i], false, 0, 0);
if (editorComponent instanceof JComboBox && ((JComboBox) editorComponent).isEditable()) {
if ( ((JComboBox) editorComponent).isEditable() ) {
ComboBoxEditor editor = ((JComboBox) editorComponent).getEditor();
if (editor instanceof BasicComboBoxEditor) {
editor.getEditorComponent().addFocusListener(focusListener);
}
} else {
editorComponent.addFocusListener(focusListener);
}
} else if (editorComponent instanceof JPanel) {
JPanel editorPanel = (JPanel) editorComponent;
Component[] components = editorPanel.getComponents();
for (Component comp : components) {
comp.addFocusListener(focusListener);
}
} else {
editorComponent.addFocusListener(focusListener);
}
panel.add(editorComponent);
panel.addFocusListener(focusListener);
}
}