jcombobox

Change background color editable JComboBox

一笑奈何 提交于 2019-12-17 16:31:12
问题 I am programming an editable combobox in a JFrame Form, but i want to change te background color. How the program works: If i click the button "press", then the combobox his background needs to become black. I tried: 1. cbo.setBackground(Color.BLACK); But it did nothing 2 cbo.getEditor().getEditorComponent().setBackground(Color.BLACK); ((JTextField) cbo.getEditor().getEditorComponent()).setOpaque(true); Does this: Code example: public class NewJFrame extends javax.swing.JFrame { private

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

Adding items to a JComboBox

瘦欲@ 提交于 2019-12-17 09:50:04
问题 I use a combo box on panel and as I know we can add items with the text only comboBox.addItem('item text'); But some times I need to use some value of the item and item text like in html select: <select><option value="item_value">Item Text</option></select> Is there any way to set both value and title in combo box item? For now I use a hash to solve this issue. 回答1: Wrap the values in a class and override the toString() method. class ComboItem { private String key; private String value;

Putting JComboBox into JTable

こ雲淡風輕ζ 提交于 2019-12-17 07:30:39
问题 I want to put individual JComboBoxes into each cells of a JTable. ie. The JComboBox content is not identical for each cell. I basically would like to be able to just call the following code to add a row of JComboBox into the JTable. Anyone has any idea? Thanks JComboBox cb1 = new JComboBox(...); JComboBox cb2 = new JComboBox(...); model.addRow(new Object[] {"Row name", cb1, cb2} ); JComboBox cb3 = new JComboBox(...); JComboBox cb4 = new JComboBox(...); model.addRow(new Object[] {"Row name 2",

how to add different JComboBox items in a Column of a JTable in Swing

时光怂恿深爱的人放手 提交于 2019-12-17 06:16:11
问题 I want to add JComboBox inside a JTable (3,3) on column 1. But in the column 1 , each row will have its own set of ComboBox element. When I tried to use table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox_Custom)); Each row is being set to same set of ComboBox Values. But I want each row ComboBox has different items. 回答1: example on java2s.com looks like as works and correctly, then for example (I harcoded JComboBoxes for quick example, and add/change for todays

JComboBox in a JTable cell

喜夏-厌秋 提交于 2019-12-17 04:07:36
问题 I have a JTable created using a model, which is based on a matrix of objects. For each row, I want to put in a specific column (the 5th) some information using a JComboBox. I have tried the following: for(int i=0; i < n ; i++) { ..... data[i][5] = new JComboBox(aux); // aux is a Vector of elements I wanna insert } table.setModel(new MyTableModel()); // MyTableModel() already takes into consideration the data[][] object The problem is that data[i][5] = new JComboBox(aux); does not create a

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 to turn off auto selection in combobox while navigating in dropdown?

天涯浪子 提交于 2019-12-14 03:18:46
问题 the Title states my problem almost completely. I have some combo box classes which derive from JComboBox, additionally we use the PlasticUI from JGoodies. My Problem is that when I navigate through the available items in the drop down popup those items are automatically being selected. This only happens when I use the navigation keys, hovering with the mouse over the objects is fine. In my case this is pretty bad because it somehow provokes the lazy-loaded data in the object to be loaded and

adding an action listener to a JComboBox

只愿长相守 提交于 2019-12-13 21:32:31
问题 I just want to print the selected option in the combo box, to a textfield. Please explain what's wrong because i have to complete it & explain it in class. Any help would be greatly appreciated. Thanks in advance. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class App3 extends JFrame implements ActionListener { private JPanel boxPanel,textPanel; private JLabel selectName,selectedName; private JComboBox nameCombo; private JTextField valueOfSelectedName; private

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