jcombobox

How do I add a separator to a JComboBox in Java?

孤人 提交于 2019-12-02 23:39:59
I have a JComboBox and would like to have a separator in the list of elements. How do I do this in Java? A sample scenario where this would come in handy is when making a combobox for font-family-selection; similar to the font-family-selection-control in Word and Excel. In this case I would like to show the most-used-fonts at the top, then a separator and finally all font-families below the separator in alphabetical order. Can anyone help me with how to do this or is this not possible in Java? There is a pretty short tutorial with an example that shows how to use a custom ListCellRenderer on

java.lang.IllegalStateException when updating JComboBox with setModel()?

て烟熏妆下的殇ゞ 提交于 2019-12-02 21:36:51
问题 I was trying to updating JComboBox with setModel(). However, it throws a java.lang.IllegalStateException. Specifically, I used a JTextField to point to the Editable component of the JComboBox, and Update the JComboBox every time the JTextField recieves a new input. Can anyone tell me the reason? package ui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import javax.swing.JFrame; import

getting Jcomponent from other class changes frame size

半腔热情 提交于 2019-12-02 18:41:26
问题 Hello I am try to get jcomponent from other class.the components are displaying but my frame size changes. Example.java public class Example extends JFrame{ static JPanel panel = new JPanel(); static A a = new A(); static B b = new B(); static JComboBox<String> combo = new JComboBox<>(); static String value; Example(){ setSize(400, 400); combo.setBounds(450, 140, 50, 20); combo.addItem(""); combo.addItem("a"); combo.addItem("b"); combo.addActionListener(new ActionListener() { @Override public

add items runtime on combobox in java

六月ゝ 毕业季﹏ 提交于 2019-12-02 15:21:15
问题 I have created a comboBox in Swing and I want to add items on it in another function. But the problem is that items are not displaying after calling that function: public void addItems() { combo.addItem(""); // i want to add items here when this function is being called // but those items are not displaying after calling this function // i m calling this function on button click } 回答1: Works for me in this SSCCE: import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt

Loading an ArrayList into a JCombobox using netbeans

心不动则不痛 提交于 2019-12-02 15:19:50
问题 Currently have an ArrayList called SundayList which is loaded as soon as the frame AddStudent is loaded (bit of GUI) The code automatically generated by Netbeans is: comboboxSunday = new javax.swing.JComboBox(); comboboxSunday.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item1", "Item2" })); How do I load the combobox items with my own array? The array includes items such as: Activity1 Activity2 Activity3 Activity4 From my previous search, people mentioned about using a

How to Cast a Vector<ObjectA> to Vector<ObjectB> in Java?

与世无争的帅哥 提交于 2019-12-02 13:13:21
问题 I am using JComboBox with a custom class object, and the equals method is over-ridden, and integrated very deeply into the code. The problem is that if two objects are equal in a JComboBox drop down, then if one is selected all are selected, and the get selected index returns -1. Is there a ways to cast a Vector<ObjectA> to a Vector<ObjectB> ? I tried Vector<Clas_2> v_temp=(ca.courses.get(i).classes); and Vector<Clas_3> v_temp=(ca.courses.get(i).classes); Where Clas_2 is a parent of Clas_1

Java - if a value selected in combox1 then it should be disable in all other combo boxes

爱⌒轻易说出口 提交于 2019-12-02 13:11:53
问题 Hello I'm still newbie on java hope to learn this nice feature... Hello i have 4 combo box that have the same inside and inside of it is -Select- Item 1 Item 2 Item 3 Item 4 and when I choose Item 1 on comboBox1 , the comboBox2,comboBox3 and comboBox4 have elements only these -Select- Item 2 Item 3 Item 4 and then when I choose Item 3 on comboBox2 , the comboBox3 and comboBox4 have this leftover elements -Select- Item 2 Item 4 anyone have idea how to do this on Java? I am using GUI Builder on

populate JTable with the value selected in Jcombobox

好久不见. 提交于 2019-12-02 13:07:14
I have a JCombobox and JTable and database jcombobox is filled with the value of first_name of student table from databse. Whenever I select a name from database I want the value of Course name from course and student_score from score table of the database to be displayed in Jtable. Basically I want to display the records of selected in JComboBox in Jtable import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import net.proteanit.sql.DbUtils; import javax.swing.JLabel; import java.awt.Font; import

getting Jcomponent from other class changes frame size

那年仲夏 提交于 2019-12-02 12:25:07
Hello I am try to get jcomponent from other class.the components are displaying but my frame size changes. Example.java public class Example extends JFrame{ static JPanel panel = new JPanel(); static A a = new A(); static B b = new B(); static JComboBox<String> combo = new JComboBox<>(); static String value; Example(){ setSize(400, 400); combo.setBounds(450, 140, 50, 20); combo.addItem(""); combo.addItem("a"); combo.addItem("b"); combo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { value = (String) combo.getSelectedItem().toString(); if(value

java.lang.IllegalStateException when updating JComboBox with setModel()?

依然范特西╮ 提交于 2019-12-02 12:01:04
I was trying to updating JComboBox with setModel(). However, it throws a java.lang.IllegalStateException. Specifically, I used a JTextField to point to the Editable component of the JComboBox, and Update the JComboBox every time the JTextField recieves a new input. Can anyone tell me the reason? package ui; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import javax.swing.DefaultComboBoxModel; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.JToolBar; import javax.swing.event