本文整理匯總了Java中java.awt.event.ItemListener類的典型用法代碼示例。如果您正苦於以下問題:Java ItemListener類的具體用法?Java ItemListener怎麽用?Java ItemListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ItemListener類屬於java.awt.event包,在下文中一共展示了ItemListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addCheckBoxToPanel
import java.awt.event.ItemListener; //導入依賴的package包/類
public void addCheckBoxToPanel(Food food) {
JFrame frame = this;
jPanel2.setLayout(new GridLayout(0, 4));
final JCheckBox box = new JCheckBox(food.getFood());
box.setActionCommand(String.valueOf(food.getId()));
box.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (box.isSelected()) {
jTextArea1.append(box.getText() + "\n");
selectedFoodIds.add(Integer.parseInt(box.getActionCommand()));
}
}
});
jPanel2.add(box);
frame.revalidate();
frame.repaint();
}
示例2: getPopupMenuItem
import java.awt.event.ItemListener; //導入依賴的package包/類
public JMenuItem getPopupMenuItem(JTextComponent target) {
item = new JCheckBoxMenuItem(NbBundle.getBundle(BaseKit.class).
getString("line-numbers-menuitem"), isLineNumbersVisible());
item.addItemListener( new ItemListener() {
public void itemStateChanged(ItemEvent e) {
actionPerformed(null,null);
}
});
return item;
}
示例3: setActivated
import java.awt.event.ItemListener; //導入依賴的package包/類
/**
* activates or deactivates the widget in the panel
* @param activated boolean true to activate and false to deactivate
*/
public void setActivated(boolean activated) {
if(widget!=null && widget.isClickable()){
widget.setActive(activated);
if(activated){
labelPanel.setBackground(highlightColor);
jLabel.setForeground(Color.GRAY);
}else{
labelPanel.setBackground(Color.GRAY);
jLabel.setForeground(highlightColor);
}
if(widget!=null){
widget.onActiveChanged();
}
//notify the listeners over the widet the state change event
for(ItemListener listener: listeners){
ItemEvent e = new ItemEvent(this,0,widget, isActivated() ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
listener.itemStateChanged(e);
}
}
}
示例4: attachListeners
import java.awt.event.ItemListener; //導入依賴的package包/類
private void attachListeners() {
localeComboBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
RP.post(new Runnable() {
@Override
public void run() {
final Set<File> jars = loadPlatformJars();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (e.getStateChange() == ItemEvent.SELECTED) {
branding.refreshLocalizedBundles((Locale) e.getItem());
prepareTree(jars);
}
}
});
}
});
}
});
}
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:InternationalizationResourceBundleBrandingPanel.java
示例5: create
import java.awt.event.ItemListener; //導入依賴的package包/類
public static GitCommitPanel create(final File[] roots, final File repository, GitUser user, boolean fromGitView) {
Preferences preferences = GitModuleConfig.getDefault().getPreferences();
String lastCanceledCommitMessage = GitModuleConfig.getDefault().getLastCanceledCommitMessage();
GitCommitParameters parameters = new GitCommitParameters(preferences, lastCanceledCommitMessage, user);
Collection<GitHook> hooks = VCSHooks.getInstance().getHooks(GitHook.class);
GitHookContext hooksCtx = new GitHookContext(roots, null, new GitHookContext.LogEntry[] {});
DiffProvider diffProvider = new DiffProvider();
final GitCommitTable gitCommitTable = new GitCommitTable();
final CommitPanel panel = parameters.getPanel();
panel.amendCheckBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
gitCommitTable.setAmend(panel.amendCheckBox.isSelected());
}
});
return new GitCommitPanel(gitCommitTable, roots, repository, parameters, preferences, hooks, hooksCtx, diffProvider, fromGitView, createFilters(fromGitView));
}
示例6: displayAlert
import java.awt.event.ItemListener; //導入依賴的package包/類
/**
* Just show the dialog but do not do anything about it.
*/
private boolean displayAlert(String projectDisplayName) {
String title = NbBundle.getMessage(UnboundTargetAlert.class, "UTA_TITLE", label, projectDisplayName);
final DialogDescriptor d = new DialogDescriptor(this, title);
d.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION);
d.setMessageType(NotifyDescriptor.ERROR_MESSAGE);
d.setValid(false);
selectCombo.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
d.setValid(((String) selectCombo.getSelectedItem()).trim().length() > 0);
}
});
Dialog dlg = DialogDisplayer.getDefault().createDialog(d);
selectCombo.requestFocusInWindow();
// XXX combo box gets cut off at the bottom unless you do something - why??
Dimension sz = dlg.getSize();
dlg.setSize(sz.width, sz.height + 30);
dlg.setVisible(true);
return d.getValue() == NotifyDescriptor.OK_OPTION;
}
示例7: DeviceSelector
import java.awt.event.ItemListener; //導入依賴的package包/類
public DeviceSelector(Controller controller) {
super(controller);
selector = new javax.swing.JComboBox();
label = new javax.swing.JLabel("");
panel = new javax.swing.JPanel(new java.awt.BorderLayout(0,1));
panel.add(label, java.awt.BorderLayout.NORTH);
panel.add(selector, java.awt.BorderLayout.SOUTH);
panel.setBorder(new javax.swing.border.EmptyBorder(3,3,3,3));
actionHash = new HashMap<String,IAction>();
//listener to combo box gets value and initiates action
selector.addItemListener( new ItemListener() {
public void itemStateChanged(ItemEvent event) {
if (event.getStateChange() == ItemEvent.DESELECTED) return;
IAction action = actionHash.get(event.getItem());
doAction(action);
}
});
}
示例8: getPopupMenuItem
import java.awt.event.ItemListener; //導入依賴的package包/類
public @Override JMenuItem getPopupMenuItem(JTextComponent target) {
Preferences prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
boolean toolbarVisible = prefs.getBoolean(SimpleValueNames.TOOLBAR_VISIBLE_PROP, EditorPreferencesDefaults.defaultToolbarVisible);
JCheckBoxMenuItem item = new JCheckBoxMenuItem(
NbBundle.getBundle(ToggleToolbarAction.class).getString("PROP_base_toolbarVisible"), //NOI18N
toolbarVisible);
item.addItemListener( new ItemListener() {
public @Override void itemStateChanged(ItemEvent e) {
actionPerformed(null,null);
}
});
return item;
}
示例9: show
import java.awt.event.ItemListener; //導入依賴的package包/類
private void show(Window window) {
JButton jButton = new JButton("Show ColorChooser");
jButton.setActionCommand("Show ColorChooser");
jButton.addActionListener(this);
this.cbPlaf = new JComboBox<UIManager.LookAndFeelInfo>(UIManager.getInstalledLookAndFeels());
this.cbPlaf.addItemListener(new ItemListener(){
@Override
public void itemStateChanged(ItemEvent itemEvent) {
if (itemEvent.getStateChange() == 1) {
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
UIManager.LookAndFeelInfo lookAndFeelInfo = (UIManager.LookAndFeelInfo)Test4319113.this.cbPlaf.getSelectedItem();
try {
UIManager.setLookAndFeel(lookAndFeelInfo.getClassName());
Frame[] arrframe = Frame.getFrames();
int n = arrframe.length;
while (--n >= 0) {
Test4319113.updateWindowTreeUI(arrframe[n]);
}
}
catch (Exception var2_3) {
System.err.println("Exception while changing L&F!");
}
}
});
}
}
});
window.add(this.cbPlaf);
window.add(jButton);
window.pack();
window.setVisible(true);
}
示例10: getJComboBoxJVMMemoryMaximum
import java.awt.event.ItemListener; //導入依賴的package包/類
/**
* This method initializes jComboBoxJVMMemoryMaximum
* @return javax.swing.JComboBox
*/
private JComboBox<String> getJComboBoxJVMMemoryMaximum() {
if (jComboBoxJVMMemoryMaximum == null) {
jComboBoxJVMMemoryMaximum = new JComboBox<String>();
jComboBoxJVMMemoryMaximum.setModel(comboModelMaximal);
jComboBoxJVMMemoryMaximum.setPreferredSize(new Dimension(80, 26));
jComboBoxJVMMemoryMaximum.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent ie) {
if (ie.getStateChange()==ItemEvent.SELECTED) {
@SuppressWarnings("unchecked")
JComboBox<String> combo = (JComboBox<String>) ie.getSource();
if (isMemorySelectionError(combo)==false) {
// --- Save in project ------------
currRemoteContainerConfiguration.setJvmMemAllocMaximum((String) jComboBoxJVMMemoryMaximum.getSelectedItem());
currProject.setRemoteContainerConfiguration(currRemoteContainerConfiguration);
} else {
// --- Set back to old value ------
getJComboBoxJVMMemoryMaximum().setSelectedItem(currRemoteContainerConfiguration.getJvmMemAllocMaximum());
}
}
}
});
}
return jComboBoxJVMMemoryMaximum;
}
示例11: createTypeMenu
import java.awt.event.ItemListener; //導入依賴的package包/類
/**
* @return menu that allows to select possible column types
*/
private JMenu createTypeMenu() {
ButtonGroup typeGroup = new ButtonGroup();
JMenu typeChangeItem = new JMenu(CHANGE_TYPE_LABEL);
typeChangeItem.setToolTipText(CHANGE_TYPE_TIP);
for (final ColumnType columnType : ColumnType.values()) {
final JCheckBoxMenuItem checkboxItem = new JCheckBoxMenuItem(
DataImportWizardUtils.getNameForColumnType(columnType));
if (columnType == metaData.getColumnMetaData(columnIndex).getType()) {
checkboxItem.setSelected(true);
}
checkboxItem.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
changeType(columnType);
}
}
});
typeGroup.add(checkboxItem);
typeChangeItem.add(checkboxItem);
}
return typeChangeItem;
}
示例12: updateOperatorCombo
import java.awt.event.ItemListener; //導入依賴的package包/類
private void updateOperatorCombo() {
Object selectedItem = this.operatorCombo.getSelectedItem();
this.operatorCombo.removeAllItems();
List<Operator> allInnerOps = parentOperator.getAllInnerOperators();
Vector<String> allOpNames = new Vector<String>();
Iterator<Operator> i = allInnerOps.iterator();
while (i.hasNext()) {
allOpNames.add(i.next().getName());
}
Collections.sort(allOpNames);
Iterator<String> s = allOpNames.iterator();
while (s.hasNext()) {
this.operatorCombo.addItem(s.next());
}
this.operatorCombo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
fireEditingStopped();
}
});
if (this.operatorCombo.getItemCount() == 0) {
this.operatorCombo.addItem("add inner operators");
}
this.operatorCombo.setSelectedItem(selectedItem);
}
示例13: addInputCombo
import java.awt.event.ItemListener; //導入依賴的package包/類
/**
* Adds an input field to select from a ComboBox
* @param text text to be shown on a label
* @param property property to be changed in Defaults
* @param cont container where input field must be added
* @param values Map with internal value <-> showed value relations
*/
protected void addInputCombo(String text, final String property, Container cont, final Map<String, String> values) {
JLabel label = new JLabel(text + ":");
JComboBox combo = new JComboBox(values.values().toArray());
combo.setName(property);
label.setLabelFor(combo);
combo.setSelectedItem(values.get(Defaults.get(property)));
// Sets maximum size to minimal one, otherwise springLayout will stretch this
combo.setMaximumSize(new Dimension(combo.getMaximumSize().width, combo.getMinimumSize().height));
combo.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
// As Map does not allows reverse mapping, scans the entire keyset to
// find the key corresponding to a given object
Object[] keys = values.keySet().toArray();
for (Object key : keys) {
if (values.get(key) == e.getItem()) {
Defaults.set(property, (String) key);
}
}
}
});
cont.add(label);
cont.add(combo);
}
示例14: addBooleanComboBox
import java.awt.event.ItemListener; //導入依賴的package包/類
/**
* Adds a ComboBox to select a boolean property
* @param text text to be shown on a label
* @param property property to be changed in Defaults
* @param cont container where input field must be added
*/
protected void addBooleanComboBox(String text, final String property, Container cont) {
JLabel label = new JLabel(text + ":");
JComboBox combo = new JComboBox(new Object[] { Boolean.TRUE.toString(), Boolean.FALSE.toString() });
combo.setName(property);
label.setLabelFor(combo);
combo.setSelectedItem(Defaults.get(property));
// Sets maximum size to minimal one, otherwise springLayout will stretch this
combo.setMaximumSize(new Dimension(combo.getMaximumSize().width, combo.getMinimumSize().height));
combo.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
Defaults.set(property, (String) e.getItem());
}
});
cont.add(label);
cont.add(combo);
}
示例15: addEnableControl
import java.awt.event.ItemListener; //導入依賴的package包/類
/**
* Add a control for enablement
*
* @param text The label to be associated with the check box
* @param listener The listener to be notified of updates to the new control
*/
private void addEnableControl(String text, ItemListener listener) {
JCheckBox enableControl = new JCheckBox("Enable " + text);
enableControl.setBounds(10, offset, 200, 20);
enableControl.addItemListener(listener);
add(enableControl);
controlToValueName.put(enableControl, text);
valueNameToControl.put(text, enableControl);
offset += 25;
}