jcombobox

jcombobox as cell editor java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location

霸气de小男生 提交于 2019-12-01 20:55:47
问题 I am using a custom JComboBox as a cell editor in a JTable. When the users gets to the cell using keyboard controls it tries to open the popup. This causes the following error: java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location at java.awt.Component.getLocationOnScreen_NoTreeLock(Component.java:1964) at java.awt.Component.getLocationOnScreen(Component.java:1938) at javax.swing.JPopupMenu.show(JPopupMenu.java:887) at javax.swing.plaf

Accessing JComboBox data from separate JForm

房东的猫 提交于 2019-12-01 20:51:49
I've spent a bit of time browsing Stack Overflow and the internet looking for the answer to my question, but I found all the answers hard to understand and I was quite unsure if any of them related to my problem, so I decided I needed help in the right context. I am creating a program that will give a series of solutions based on a particular type of graph inputted. I am sincerely struggling with taking the data from my JComboBox in the first JFrame, and displaying it in the second. I have two classes, GraphEquationSolverGUI and DefineEquation. I am using the Netbeans IDE and

jcombobox as cell editor java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location

女生的网名这么多〃 提交于 2019-12-01 20:50:38
I am using a custom JComboBox as a cell editor in a JTable. When the users gets to the cell using keyboard controls it tries to open the popup. This causes the following error: java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location at java.awt.Component.getLocationOnScreen_NoTreeLock(Component.java:1964) at java.awt.Component.getLocationOnScreen(Component.java:1938) at javax.swing.JPopupMenu.show(JPopupMenu.java:887) at javax.swing.plaf.basic.BasicComboPopup.show(BasicComboPopup.java:191) at javax.swing.plaf.basic.BasicComboBoxUI

Local variable needs to be declared final

℡╲_俬逩灬. 提交于 2019-12-01 19:42:40
I'm receiving the error "local variable box is accessed from within inner class; needs to be declared final". That seems alright, but I don't really think it's the best solution, so I was hoping maybe someone else can help me out. Here is my code: public void showPublisherBox(JComboBox box) { if (publisherBox == null) { publisherBox = new AddPublisherForm(); publisherBox.setLocationRelativeTo(this); } publisherBox.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { this.populatePublishers(box); } private void populatePublishers(JComboBox box){ box.setModel(db

Values of JComboBox

自闭症网瘾萝莉.ら 提交于 2019-12-01 18:47:41
Is it possible, to define values different from the actual content in a JComboBox? In HTML it looks as follows: <select> <option value="value1">Content1</option> <option value="value2">Content2</option> <option value="value3">Content3</option> </select> Here it's possible to get a short value, no matter how long its content is. In Java I only know the following solution: // Creating new JComboBox with predefined values String[] petStrings = { "Bird", "Cat", "Dog", "Rabbit", "Pig" }; private JComboBox combo = new JComboBox(petStrings); // Retrieving selected value System.out.println(combo

Java: Swing JComboBox, is it possible to have hidden data for each item in the list?

≯℡__Kan透↙ 提交于 2019-12-01 15:57:48
问题 JComponents can obtain hidden data using setName() and getName() , right? What about JComboBox items? (I'm referring to the items in the JComboBox, NOT the JComboBox itself) What if I have a JComboBox, and inside it I have a list of usernames (for example), now I want to have something like 'id' for each username in the list according to how they are ordered, what's the best way to do this? 回答1: import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax

Dynamic jcombobox items inside jtable

99封情书 提交于 2019-12-01 14:43:32
I am trying to create a Jtable with two combobox in each row. I have checked for tutorials on that and found that I can add static data inside combobox. But how come I can have dynamic data loaded into a combobox. Even, whenever the user selects the combobox 1 from the row, then based on that, the combobox 2 will be updated. Can anybody help me on this? If I do removeAllItems() from the combobox, then the combobox 2 will updated, but I am unable to add new entries. Thanks in advance. Table has two columns both are rendered as JComboBox. Now, selection of Column-2 items are dependent on the

JComboBox how to compute for two integers from two JComboBox and have the result in a JTextfield when clicking the JButton

风格不统一 提交于 2019-12-01 14:29:20
I have 2 JComboBox consisting of numbers combobox1= 1 to 5 and c ombobox2= 1 to 6. and when I click my JButton , I want the two chosen numbers to be added and shown on a Textfield. I already have the complete code except for the calculation and how to have the result in the textfield. import javax.swing.*; import java.awt.*; import java.awt.event.*; public class exer1 extends JFrame{ JFrame form = new JFrame ("haay"); JButton btn = new JButton ("Compute"); JTextField txt = new JTextField (10); JComboBox cb1 = new JComboBox(); JComboBox cb2 = new JComboBox(); public exer1(){ form.getContentPane

Java JComboBox is it possible to set editable true into one item only?

三世轮回 提交于 2019-12-01 14:29:07
i want to create a JComboBox that have a three items on it.. I want to set editable only to the last item of the JComboBox for example: JComboBox cb = new JComboBox(); cb.addItem("Dog"); cb.addItem("Cat"); cb.addItem("Other"); when i drop down the JComboBox and choose the item Others.. JComboBox became editable.. how can I do that? You can use an ItemListener to know which item is selected and then you can set the JComboBox editable as needed. Try this example: import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import

Change Cell Editor for specific Cells with AbstractTableModel

南笙酒味 提交于 2019-12-01 12:42:51
I have a written an AbstractTableModel for my JTable in my application. I see from tutorials that I can make the column to have a combobox by getting the column model and then the specific column for example: TableColumn sportColumn = table.getColumnModel().getColumn(2); ... JComboBox comboBox = new JComboBox(); comboBox.addItem("Snowboarding"); comboBox.addItem("Rowing"); comboBox.addItem("Chasing toddlers"); comboBox.addItem("Speed reading"); comboBox.addItem("Teaching high school"); comboBox.addItem("None"); sportColumn.setCellEditor(new DefaultCellEditor(comboBox)); But how do I do this