javax.swing.JComboBox.addItemListener()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(276)

本文整理了Java中javax.swing.JComboBox.addItemListener()方法的一些代码示例,展示了JComboBox.addItemListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JComboBox.addItemListener()方法的具体详情如下:
包路径:javax.swing.JComboBox
类名称:JComboBox
方法名:addItemListener

JComboBox.addItemListener介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

JComboBox box = new JComboBox();
box.addItem("One");
box.addItem("Two");
box.addItem("Four");
box.addItemListener(new ItemListener(){
  public void itemStateChanged(ItemEvent e){
    System.out.println(e.getItem() + " " + e.getStateChange() );
frame.getContentPane().add(box);
frame.pack();
frame.setVisible(true);

代码示例来源:origin: runelite/runelite

JLabel title = new JLabel(name);
title.setForeground(Color.WHITE);
title.setToolTipText("<html>" + name + ":<br>" + listItem.getDescription() + "</html>");
  JPanel item = new JPanel();
  item.setLayout(new BorderLayout());
  item.setMinimumSize(new Dimension(PANEL_WIDTH, 0));
  name = cid.getItem().name();
  JLabel configEntryName = new JLabel(name);
  configEntryName.setForeground(Color.WHITE);
  configEntryName.setToolTipText("<html>" + name + ":<br>" + cid.getItem().description() + "</html>");
    JPanel dimensionPanel = new JPanel();
    dimensionPanel.setLayout(new BorderLayout());
    dimensionPanel.add(new JLabel(" x "), BorderLayout.CENTER);
    dimensionPanel.add(heightSpinner, BorderLayout.EAST);
    JComboBox box = new JComboBox(type.getEnumConstants());
    box.setPreferredSize(new Dimension(box.getPreferredSize().width, 25));
    box.setRenderer(new ComboBoxListRenderer());
    box.addItemListener(e ->

代码示例来源:origin: pentaho/mondrian

tree.addTreeSelectionListener(this);
JComboBox listEditor = new JComboBox(
  new String[]{
    getResourceConverter().getString(
    24)); // Do not remove this
listEditor.addItemListener(
  new ItemListener() {
    public void itemStateChanged(ItemEvent e) {

代码示例来源:origin: stackoverflow.com

void inspect(int thing) {
  removeAll();
  if (thing == 0) { // nothing
    add(new JLabel("Nothing selected")); 
  } else if (thing == 1) { // face
    JComboBox faceColors = new JComboBox(
      new String[] { "Green", "Yellow", "Magenta" });
    faceColors.addItemListener(...);
    add(faceColors);
  } else {
    // etc
  }
  pack();
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) 
 {
     //elements to be shown in the combo box
   String course[] = {"", "A", "B", "C"};
   JFrame frame = new JFrame("Creating a JComboBox Component");
   JPanel panel = new JPanel();
   JComboBox combo = new JComboBox(course);
   final JButton button = new JButton("Save");
   panel.add(combo);
   panel.add(button);
     //disables the button at the start
   button.setEnabled(false);
   frame.add(panel);
   combo.addItemListener(new ItemListener() {
     public void itemStateChanged(ItemEvent ie) {
             //enables the button when an item is selected
       button.setEnabled(true);
     }
   });
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setSize(400, 400);
   frame.setVisible(true);
 }

代码示例来源:origin: stackoverflow.com

public void myClass implements ItemListener {

  String[] choices = {"Choice 1", "Choice 2", "Choice 3", "etc..."};

  public myClass() {
    JComboBox myComboBox = new JComboBox(choices);
    myComboBox.addItemListener(this);
    JLabel myLabel = new JLabel("Hello World");
    // You still will need to extend JFrame in this class if you so choose
    // The main purpose of showing a class is to show that you need to
    // Implement ItemListener
  }

  // Your other stuff here

  @Override
  public void itemStateChanged(ItemEvent e) {
    if(e.getStateChanged() == ItemEvent.SELECTED) {
      myLabel.setText(e.getItem().toString());
    }
  }
}

代码示例来源:origin: abc9070410/JComicDownloader

private void setOtherTablePanel( JPanel panel )
{
  // 下載小說封面的相關設置
  coverCheckBox = getCheckBox( "搜尋並下載小說封面圖", "search & download the novel cover", SetUp.getDownloadNovelCover() );
  CommonGUI.setToolTip( coverCheckBox, "小說下載後,以Google圖片搜尋適合的封面圖" );
  
  errorRecordCheckBox = getCheckBoxBold( "產生錯誤紀錄", "output error record", SetUp.getOutputErrorRecord() );
  CommonGUI.setToolTip( errorRecordCheckBox, "如果沒有勾選就不會在程式資料夾產生錯誤紀錄檔" );
  if ( SetUp.getDefaultLanguage() == LanguageEnum.ENGLISH )
  {
    coverStrings = new CommonGUI().getCoverEnStrings(); // 取得所有介面名稱
  }
  else
  {
    coverStrings = new CommonGUI().getCoverStrings(); // 取得所有介面名稱
  }
  coverBox = getComboBox( coverStrings, SetUp.getCoverSelectAmountIndex() );
  coverBox.addItemListener( new ItemHandler() ); // change skin if change skinBox
  CommonGUI.setToolTip( coverBox, "以小說關鍵字搜尋後,取前面數來N張圖,從中挑選出最適合的封面" );
  JPanel coverPanel = new JPanel();
  coverPanel.setLayout( new GridLayout( 1, 2, 5, 5 ) );
  coverPanel.add( coverCheckBox );
  coverPanel.add( coverBox );
  coverPanel.setOpaque( !SetUp.getUsingBackgroundPicOfOptionFrame() );
  JPanel otherPanel = new JPanel( new GridLayout( 6, 1, 2, 2 ) );
  otherPanel.add( coverPanel );
  otherPanel.add( errorRecordCheckBox );
  otherPanel.setOpaque( !SetUp.getUsingBackgroundPicOfOptionFrame() );
  panel.add( otherPanel );
}

代码示例来源:origin: org.activecomponents.jadex/jadex-applications-bdiv3

moodtf = pp.createTextField("Current mood:");
JComboBox jmb = pp.createComboBox("Select new mood: ", new Mood[]{Mood.SAD, Mood.HAPPY, Mood.ANGRY, Mood.DISAPPOINTED});
jmb.addItemListener(new ItemListener()
getContentPane().add(pp, BorderLayout.CENTER);
pack();
setVisible(true);

代码示例来源:origin: nodebox/nodebox

final JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
mainPanel.setBorder(new Theme.InsetsBorder(10, 10, 10, 10));
final JPanel formatPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 10));
formatPanel.add(new JLabel("Format:"));
formatBox = new JComboBox<>();
formatBox.addItem("SVG");
formatBox.addItem("PNG");
formatPanel.add(formatBox);
final JPanel delimiterPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 10));
delimiterPanel.add(new JLabel("Delimiter:"));
delimiterBox = new JComboBox<>();
delimiterBox.addItem(new Delimiter(',', ","));
delimiterBox.addItem(new Delimiter(';', ";"));
final JPanel quotesPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 10, 10));
quotesPanel.add(new JLabel("Quotes:"));
quotesBox = new JCheckBox("Escape output using quotes", true);
quotesPanel.add(quotesBox);
formatBox.addItemListener(new ItemListener() {
  @Override
  public void itemStateChanged(ItemEvent e) {

代码示例来源:origin: net.sf.sfac/sfac-core

public void toolbarCreated(ActionRepository repo, JToolBar toolbar) {
  int insertIndex = toolbar.getComponentCount() - 4;
  toolbar.setBorder(new PartialLineBorder(new Color(153, 153, 153), PartialLineBorder.BOTTOM, 2));
  toolbar.add(new JLabel("Current Profile:"), insertIndex);
  toolbar.add(Box.createHorizontalStrut(4), insertIndex + 1);
  profilesCombo = new JComboBox(profiles);
  Dimension preferred = profilesCombo.getPreferredSize();
  profilesCombo.setMaximumSize(preferred);
  profilesCombo.addItemListener(new ItemListener() {
    public void itemStateChanged(ItemEvent e) {
      if (e.getStateChange() == ItemEvent.SELECTED) {
        checkActionStates();
        refreshProfile();
      }
    }
  });
  toolbar.add(profilesCombo, insertIndex + 2);
  toolbar.add(Box.createHorizontalGlue());
}

代码示例来源:origin: stackoverflow.com

Container pane = f.getContentPane();
final JTextField field = new JTextField();
pane.add(field);
pane.add(new JTextField(), BorderLayout.NORTH);
JComboBox b = new JComboBox();
b.addItem("Don't focus");
b.addItem("Focus");
b.addItemListener(new ItemListener() {
  @Override
  public void itemStateChanged(ItemEvent e) {
pane.add(b, BorderLayout.SOUTH);
f.setLocationRelativeTo(null);
f.setVisible(true);

代码示例来源:origin: lbalazscs/Pixelitor

public CardPanelWithCombo() {
  super(new BorderLayout());
  selectorModel = new DefaultComboBoxModel<>();
  JComboBox<String> selector = new JComboBox<>(selectorModel);
  selector.addItemListener(this);
  JPanel northPanel = new JPanel();
  northPanel.setLayout(new FlowLayout());
  northPanel.add(selector);
  add(northPanel, BorderLayout.NORTH);
  cardPanel = new JPanel();
  cardPanel.setLayout(new CardLayout());
  add(cardPanel, BorderLayout.CENTER);
}

代码示例来源:origin: stackoverflow.com

JComboBox combo = new JComboBox();
combo.addItemListener(new ItemListener() {
 @Override
 public void itemStateChanged(ItemEvent arg0) {
 // TODO: Action.
 }
});

代码示例来源:origin: net.sf.taverna.t2.ui-activities/component-activity-ui

public LicenseChooserPanel() {
  super();
  licenseBox.setPrototypeDisplayValue(LONG_STRING);
  this.setLayout(new GridBagLayout());
  GridBagConstraints gbc = new GridBagConstraints();
  gbc.gridx = 0;
  gbc.gridy = 0;
  gbc.anchor = WEST;
  gbc.fill = NONE;
  this.add(new JLabel("License:"), gbc);
  gbc.gridx = 1;
  gbc.weightx = 1;
  gbc.fill = BOTH;
  this.add(licenseBox, gbc);
  licenseBox.setEditable(false);
  licenseBox.addItemListener(new ItemListener() {
    @Override
    public void itemStateChanged(ItemEvent event) {
      if (event.getStateChange() == SELECTED)
        setLicense(licenseMap.get(licenseBox.getSelectedItem()));
    }
  });
}

代码示例来源:origin: org.cytoscape/network-analyzer-impl

@Override
protected JComponent addSettingsPanels(JTabbedPane aPanel) {
  addTab(aPanel, Messages.DI_GENERAL, new SettingsPanel(general), Messages.TT_GENSETTINGS);
  addTab(aPanel, Messages.DI_AXES, new SettingsPanel(settings.axes), Messages.TT_AXESSETTINGS);
  addTab(aPanel, Messages.DI_GRID, new SettingsPanel(settings.grid), Messages.TT_GRIDSETTINGS);
  boolean useScatter = settings.useScatter();
  final Box histPanel = Box.createVerticalBox();
  final JComboBox choiceCombo = addChoice(histPanel, useScatter ? 1 : 0);
  final CardLayout innerLayout = new CardLayout();
  final JPanel innerPanel = new JPanel(innerLayout);
  histPanel.add(innerPanel);
  aPanel.addTab(Messages.DI_HISTOGRAM, null, histPanel, Messages.TT_HISTSETTINGS);
  ItemListener listener = new ItemListener() {
    public void itemStateChanged(ItemEvent e) {
      if (e.getStateChange() == ItemEvent.SELECTED) {
        innerLayout.next(innerPanel);
      }
    }
  };
  choiceCombo.addItemListener(listener);
  innerPanel.add(new SettingsPanel(settings.bars), "0");
  innerPanel.add(new SettingsPanel(settings.scatter), "1");
  if (useScatter) {
    innerLayout.next(innerPanel);
  }
  return choiceCombo;
}

代码示例来源:origin: stackoverflow.com

int height = 100;
gui = new JPanel(new BorderLayout(3,4));
gui.add(quality, BorderLayout.WEST);
JPanel controls = new JPanel(new GridLayout(0,1,0,0));
antialiasing = new JCheckBox("Anti-aliasing", false);
rendering = new JCheckBox("Rendering - Quality", true);
dithering = new JCheckBox("Dithering", false);
controls.add(antialiasing);
controls.add(fractionalMetrics);
textAntialiasing = new JComboBox(VALUES_TEXT_ANTIALIASING);
controls.add(textAntialiasing);
dithering.addItemListener(itemListener);
textAntialiasing.addItemListener(itemListener);
textLcdContrast.addItemListener(itemListener);
JPanel images = new JPanel(new GridLayout(0,1,2,2));
images.add(new JLabel(new ImageIcon(textImage)));

代码示例来源:origin: org.activecomponents.jadex/jadex-editor-bpmn

public ConfigComboBox(ConfigurationModel model, final AbstractTableModel tmodel)
{
  setLayout(new GridBagLayout());
  JLabel label = new JLabel("Configuration");
  GridBagConstraints gc = new GridBagConstraints();
  add(label, gc);
  combobox = new JComboBox(model);
  combobox.setMinimumSize(new Dimension(200, (int) combobox.getMinimumSize().getHeight()));
  gc = new GridBagConstraints();
  gc.gridx = 1;
  gc.weightx = 1.0;
  gc.weighty = 1.0;
  gc.fill = GridBagConstraints.BOTH;
  gc.insets = new Insets(5, 5, 0, 0);
  add(combobox, gc);
  
  if (tmodel != null)
  {
    combobox.addItemListener(new ItemListener()
    {
      public void itemStateChanged(ItemEvent e)
      {
        tmodel.fireTableStructureChanged();
      }
    });
  }
}

代码示例来源:origin: stackoverflow.com

JComboBox petList1 = new JComboBox(petStrings);
petList1.addItemListener(this);
petList1.setName("petList1");
JComboBox petList2 = new JComboBox(petStrings);
petList2.setSelectedIndex(4);
petList2.addItemListener(this);
petList2.setName("petList2");
JComboBox petList3 = new JComboBox(petStrings);
petList3.setSelectedIndex(4);
petList3.addItemListener(this);
petList3.setName("petList3");
getContentPane().add(petList1);
getContentPane().add(petList2);
getContentPane().add(petList3);

代码示例来源:origin: org.zaproxy/zap

public HttpPanelComponentViewsManager(String configurationKey) {
  enabledViews = new ArrayList<>();
  viewItems = new HashMap<>();
  views = new HashMap<>();
  defaultViewsSelectors = new ArrayList<>();
  
  isEditable = false;
  this.configurationKey = configurationKey;
  this.viewsConfigurationKey = "";
  
  changingComboBoxLocker = new Object();
  changingComboBox = false;
  
  savedSelectedViewName = null;
  comboBoxModel = new SortedComboBoxModel<>();
  comboBoxSelectView = new JComboBox<>(comboBoxModel);
  comboBoxSelectView.addItemListener(this);
  panelViews = new JPanel(new CardLayout());
}

代码示例来源:origin: violetumleditor/violetumleditor

public ColorEditor()
{
  combo = new JComboBox(colors);
  combo.addItemListener(new ItemListener()
  {
    public void itemStateChanged(ItemEvent event)
    {
      Color value = ((ColorIcon) combo.getSelectedItem()).getColor();
      setValue(value);
    }
  });
}

相关文章

JComboBox类方法