itemlistener

Java: JCheckBox won't stay checked with ItemListener

≯℡__Kan透↙ 提交于 2019-12-25 08:48:51
问题 Ok, I'm new to listeners (still learning the language), and this is my first full-scale attempt to implement them (ie more than just a practice problem in a textbook). So far, everything is working fine except one big bug: the checkboxes don't stay checked. The ItemListener I assign them runs perfectly (I have a JOptionPane set up to trigger to let me know if it's working or not), but the box itself doesn't stay checked. I went even further and added conditional logic for if it's state is

In Swing, Enter Key not working in selecting an element from a combobox

浪子不回头ぞ 提交于 2019-12-20 07:33:54
问题 I have added an ItemListener to a JComboBox. The ItemListener is able to detect any selection I make using Mouse click or space-bar. But it is not recognizing the Enter Key. In other words, if I use arrow key to scroll through entries in ComboBox and then hit Enter, then the itemStateChanged method is not invoked. Do you have any ideas? 回答1: for listening of changes from MouseEvent is there ItemListener , firing SELECTED/DESELECTED for listening of ENTER key pressed is there ActionListener

How to update JComboBox instances in Swing?

≯℡__Kan透↙ 提交于 2019-12-19 04:11:29
问题 I've 3 comboboxes, upon selecting first combobox, the rest should be updated but my code doesn't seems to be working. Please help in this guys. Here is my code(since my code very long so I'll write error part only). // example code public class GuiComponents { JComboBox<String> comboBox1, comboBox2, comboBox3; public GuiComponents() { ......... ......... String[] element1 = {"item1", "item2", "item3"}; String[] element2 = {"item1", "item2", item3}; String[] element3 = {"item1", "item2",

Why is itemStateChanged on JComboBox is called twice when changed?

吃可爱长大的小学妹 提交于 2019-12-17 11:19:42
问题 I'm using a JComboBox with an ItemListener on it. When the value is changed, the itemStateChanged event is called twice. The first call, the ItemEvent is showing the original item selected. On the second time, it is showing the item that has been just selected by the user. Here's some tester code: public Tester(){ JComboBox box = new JComboBox(); box.addItem("One"); box.addItem("Two"); box.addItem("Three"); box.addItem("Four"); box.addItemListener(new ItemListener(){ public void

JComboBox Selection Change Listener?

℡╲_俬逩灬. 提交于 2019-12-16 22:29:07
问题 I'm trying to get an event to fire whenever a choice is made from a JComboBox . The problem I'm having is that there is no obvious addSelectionListener() method. I've tried to use actionPerformed() , but it never fires. Short of overriding the model for the JComboBox , I'm out of ideas. How do I get notified of a selection change on a JComboBox ?** Edit: I have to apologize. It turns out I was using a misbehaving subclass of JComboBox , but I'll leave the question up since your answer is good

How do I update a JLabel everytime a JComboBox changes?

北城余情 提交于 2019-12-13 20:05:41
问题 I have a JComboBox with 12 different selections, and depending on what is selected I want the question (JLabel) to change matching the selection. I've tried an if statement to see what is selected and if it matches what should be selected, then the question changes accordingly, but the JLabel never really changes under an circumstance. Code import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; import java.io.IOException; import javax.imageio.ImageIO; import javax

How do I get the previous or last item?

天涯浪子 提交于 2019-12-12 12:15:15
问题 How do I get the last or previous or unselected item and then the new item for a JComboBox ? 回答1: I assume this applies to all Objects that allow for which you to add Item Listeners to them. String[] items = {"item 1","item 2"," item 3","item 4"}; JComboBox combo = new JComboBox(items) combo.addItemListener(new ItemListener(){ public void itemStateChanged(ItemEvent ie) { if(ie.getStateChange() == ItemEvent.DESELECTED) //edit: bracket was missing { System.out.println("Previous item: " + ie

JToggleButton addItemListener seems to repeat the ItemListener forever

我是研究僧i 提交于 2019-12-10 17:16:24
问题 I'm programming a JToggleButton to load to/discard from memory the configuration of an element (a telescope config), so I've added a JComboBox in a JFrame and near it the button to load the selected item. When the JToggleButton is selected, an hard disk icon is displayed, another icon if otherwise. I'm using the IntelliJ IDEA GUI editor for that. Of course, I've added an ItemListener (as suggested from the web) to that button: loadTelescopeButton.setSelected(true); System.out.println

AutoCompleteDecorator is interrupting ItemListener

守給你的承諾、 提交于 2019-12-08 11:42:39
问题 I have an editable JComboBox which is integrated with the AutoCompleteDecorator of SwingX library. My JComboBox is also having an ItemListener registered to it as well. Now, Please have a look at the below code. AutoCompleteDecorator.decorate(ClientNameCombo); ClientNameCombo.addItemListener(new ClientNameComboAction()); private class ClientNameComboAction implements ItemListener { @Override public void itemStateChanged(ItemEvent e) { String selectedClientName= ClientNameCombo.getSelectedItem

How to update JComboBox instances in Swing?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 00:40:24
I've 3 comboboxes, upon selecting first combobox, the rest should be updated but my code doesn't seems to be working. Please help in this guys. Here is my code(since my code very long so I'll write error part only). // example code public class GuiComponents { JComboBox<String> comboBox1, comboBox2, comboBox3; public GuiComponents() { ......... ......... String[] element1 = {"item1", "item2", "item3"}; String[] element2 = {"item1", "item2", item3}; String[] element3 = {"item1", "item2", "item3"}; comboBox1.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent