jcombobox

Set Size of JComboBox PopupMenu

这一生的挚爱 提交于 2019-11-28 00:21:19
i am programming a custom component which extends a JComboBox. My problem is, the PopupMenu won't actualise its size if i am adding or removing an item. So there are e.g. 2 items in the list, but if there were 4 before i had 2 "empty" items in the PopupMenu as well. The only workaround i found was to do (in JIntelligentComboBox.java line 213) this.setPopupVisible(false); this.setPopupVisible(true); but the result will be a flickering PopupMenu :-( So what else could i do to refresh/repaint the PopupMenu without flickering? For testing: the component and a little test programm To generate my

JComboBox change drop-down popup

橙三吉。 提交于 2019-11-28 00:19:42
basically is popup for a JComboBox displayed below its derived JTextField, how can change direction from bellowed orientations for JComboBox's popup and display JComboBox's popup on the top/over that EDIT: code example for basic JComboBox import java.awt.Dimension; import javax.swing.*; import javax.swing.plaf.basic.BasicComboBoxRenderer; public class HighRowCombo { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new HighRowCombo().makeUI(); } }); } public void makeUI() { Object[] data = {"One", "Two with text", "Three with

Change background color editable JComboBox

拈花ヽ惹草 提交于 2019-11-27 23:20:03
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 JComboBox cboCategorie; public NewJFrame() { initComponents(); cboCategorie = new JComboBox(); cboCategorie

Celleditor (JComboBox) in a specific row of a JTable

大憨熊 提交于 2019-11-27 22:53:07
问题 I don't know how to do to set a jcombobox in a specific row...for now I've this jcombobox for all rows but I want it in only one row: JComboBox cc = new JComboBox(); cc.addItem(jComboBox5.getSelectedItem()+"/"+jComboBox6.getSelectedItem()+"/"+jComboBox7.getSelectedItem()+" "+jComboBox1.getSelectedItem()+"."+jComboBox2.getSelectedItem()); jTable1.getColumnModel().getColumn(3).setCellEditor(new DefaultCellEditor(cc)); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer

Dynamically change JComboBox

这一生的挚爱 提交于 2019-11-27 15:43:49
问题 I am fetching the data values from the database successfully. I have also stored them into a String[] array. I need to load the String array as the items of the JComboBox in response to key actionperformed. How can I reload the items of the JComboBox whenever a key is pressed as the fetched values depend on the key pressed. Rather simply, I need to dynamically refresh the JComboBox items. 回答1: DefaultComboBoxModel model = new DefaultComboBoxModel( yourStringArray ); comboBox.setModel( model )

How to use Map element as text of a JComboBox

限于喜欢 提交于 2019-11-27 15:09:29
I am populating a JComboBox (using addItem() ) with all the elements of a collection. Each element in the collection is a HashMap (so its a ComboBox of Hashmaps..). My question is - Given that I need each item to be a HashMap how do I set the text to apear in the combobox on the GUI? It needs to be the value of a certain key in the map. Normally if I am populating a combobox with my own type, I would just overide the toString() method...but I am not sure how to acheive this since I am using a Java HashMap. Any ideas (if possible, without implementing my own HashMap)? Update : It seems like

JCombobox change another JCombobox

痴心易碎 提交于 2019-11-27 14:54:23
I'm trying to combine 2 jcomboboxes. 1 combobox is for showing category of expences. and second combobox is reading file from text file to show types of products. If I change first combobox I would like that second combobox will change based on what user select in the first one. Is there any chance that i can still load the other combobox from text files? That subitems would not be Arrays but same as before as it is on the bottom of the code to cboperson. edited code: private JComboBox cboCategory; private JComboBox cboPerson; private JComboBox cboItem; public String itemChange = "groceries

how to trigger an action in parent JPanel when a component in a child JPanel is updated (Java Swing)

只愿长相守 提交于 2019-11-27 14:29:47
I am trying to build an MVC application in Java Swing. I have a JPanel that contains four JComboBoxes and this JPanel is embedded into a parent JPanel. The parent JPanel has other controls in addition to the child JPanel. The child JPanel's model gets correctly updated whenever I change the values of the JComboBoxes (it's basically a date picker with one combo box each for year, month, day of month, and hour of day). What I cannot figure out is how I can trigger the parent JPanel's model to update itself to match the value stored in the child JPanel's model whenever one of the JComboBoxes is

How do I populate JComboBox from a text file?

若如初见. 提交于 2019-11-27 09:37:32
How do I populate a JComboBox from a text file? Very vague question. Are you saying you want one entry per line? If so you want to use something like a BufferedReader, read all the lines, save them as a String array. Create a new JComboBox passing in that String constructor. BufferedReader input = new BufferedReader(new FileReader(filePath)); List<String> strings = new ArrayList<String>(); try { String line = null; while (( line = input.readLine()) != null){ strings.add(line); } } catch (FileNotFoundException e) { System.err.println("Error, file " + filePath + " didn't exist."); } finally {

Binding comboboxes in swing

大城市里の小女人 提交于 2019-11-27 09:37:23
I'm working on a desktop (swing) application with Eclipse IDE. I have three comboboxes (countries, states and cities) and I need to update the data automatically when I selecting a new country or province. I searched lot of information, but all the implementations I found are made on Ajax or the beansbinding framework in NetBeans. I tried a solution by ItemEvent, but I have problems starting my application it loads the list of countries but not the other lists. And by selecting a country is charged the list of states but not the list of cities. My code: jComboBoxCountries.addItemListener(new