jcombobox

Get input values from JComboBox

可紊 提交于 2019-11-28 09:49:23
问题 How can I get the input for an editable JComboBox . When user gives an input to the combo how I can get the input text from it? 回答1: You need to get the edited text from the combobox editor via combo.getEditor().getItem(). 回答2: If you need the text that is selected on a JComboBox and you are sure it's a String and not any other object, just use something like String text = (String)myCombobox.getSelectedItem() . If the thing you have in your Model is other than a String , then you need to cast

JComboBox popup is not resized if i add item when it is visible

左心房为你撑大大i 提交于 2019-11-28 06:14:44
问题 I have a problem with a JComboBox popup. My JComboBox has an autocompletition implementation like google search box. So, the problem is if I add or remove items when popup is visible it is not resized, I need to close and reopen it. But this fire popupBecomeInvisible and popupBecomeVisible and so i can't use this events for my real porpouse. There is a way to "refresh" popup size in according to count of items that it contains, without close and reopen it? Thanks. 回答1: Invoke revalidate() on

Sharing same model between two JComboBoxes

爷,独闯天下 提交于 2019-11-28 05:55:00
问题 I have a Person [ ] with three Persons (p1,p2,p3). Person class has two attributes name and email . I want to add all names of Person[] in one JComboBox and all emails in another JComboBox. I used the following code. Person p1 = new Person("Smith", "smith@mail.com"); Person p2 = new Person("Tom", "tom@gmail.com"); Person p3 = new Person("John","john@mail.com"); Person[] per_arr = new Person[] { p1, p2, p3}; JFrame frame = new JFrame(); JPanel panel = new JPanel(); JComboBox<String> combo1 =

How to sort the jComboBox elements in java swing?

戏子无情 提交于 2019-11-28 05:36:22
问题 How to sort the jComboBox elements list into sorted list. JComboBox box=new JComboBox(); box.addItem("abc"); box.addItem("zzz"); box.addItem("ccc"); add(box); i used many jComboBox Components but it's not working. How to sort this list into ascending order? 回答1: You can have a look at the SortedComboBoxModel. This model extends the DefaultComboBoxModel and has two additional pieces of functionality built into it: upon creation of the model, the supplied data will be sorted before the data is

How to use ActionListener on a ComboBox to give a variable a value

廉价感情. 提交于 2019-11-28 04:41:04
问题 Im using BlueJ and I have run into problem. I have a combo box with 3 options. Each option is a string. The three options are Day, Week, and Month. What I want to do is if Day is picked than a variable equals 30 (a double) and so on. Can someone help me buy telling me how to give "emailvalue" a value based on the selected option in the combobox? EDIT: Im going to add my actual program code which is a monthly data calculater. It does compile. Here is the code: import javax.swing.*; import java

How to configure JComboBox not to select FIRST element when created?

冷暖自知 提交于 2019-11-28 03:46:08
问题 Problem: Update: From the Java SE 6 API: public JComboBox() Creates a JComboBox with a default data model. The default data model is an empty list of objects. Use addItem to add items. By default the first item in the data model becomes selected. So I changed to JComboBox(model) as the API says: public JComboBox(ComboBoxModel aModel) Creates a JComboBox that takes its items from an existing ComboBoxModel. Since the ComboBoxModel is provided, a combo box created using this constructor does not

JComboBox to list age

雨燕双飞 提交于 2019-11-28 02:22:27
Purpose: JComboBox to list down ages that a user can select I realize that I need an array of integers. What part of the Math functions in Java will allow me to easily do that? The list of numbers will be from 1-100 in sequential order. Adel Boutros I don't quite understand why you need the Math functions. This would work: List<Integer> age = new ArrayList<Integer>(); for (int i = 1; i <= 100; ++i) { age.add(i); } JComboBox ageComboBox = new JComboBox(age.toArray()); You don't need any math functions. Look up JComboBox in the java docs and you'll find a .addItem function. It can take a String

Why JComboBox ignore PrototypeDisplayValue

会有一股神秘感。 提交于 2019-11-28 01:17:30
In connections with these two post @iMohammad, Increasing/Decreasing Font Size inside textArea using JButton and Changing Font Style when Clicking on a JButton Java ..., I'm facing with really funny issue that came from JComboBox by passing setPrototypeDisplayValue as an argument for JComboBox's size on the screen please how can I resize JComboBox dynamically depends of Font , same as works correctly for another JComponents that I tried in my sscce import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ComboBoxFontChange extends JFrame { private static final long

java swing multi column autocomplete combobox

时光毁灭记忆、已成空白 提交于 2019-11-28 00:37:38
I need efficient product item search GUI to Point of sale application, currently I am using pop up in text field and it include to table but it is not efficient. In my popup only show product code I need to show other product detail such as CODE , category, Name ,price etc.. to determine correct product. ![enter image description here][1] Following images are the my requirement. ////////////////////////////// I have Edit mr.splungebob answer to build AutoCompleate combobox , But It has problem with List> filtering please review code and help me to develop it. Following are the code I have

JComboBox returning values

老子叫甜甜 提交于 2019-11-28 00:23:15
What method is used to return the selection chosen by the user? JPanel ageSelection = new JPanel(); JLabel age = new JLabel("Age:"); ArrayList<Integer> ageList = new ArrayList<Integer>(); for (int i = 1; i <= 100; ++i) { ageList.add(i); } DefaultComboBoxModel<Integer> modelAge = new DefaultComboBoxModel<Integer>(); for (Integer i : ageList) { modelAge.addElement(i); } JComboBox<Integer> ageEntries = new JComboBox<Integer>(); ageEntries.setModel(modelAge); ageEntries.addActionListener(new putInTextListener()); ageSelection.add(age); ageSelection.add(ageEntries); class putInTextListener