jcombobox

Updating JComboBox

≡放荡痞女 提交于 2019-12-11 13:39:29
问题 So I'm using a JComboBox with an ArrayList : protected JComboBox<String> jcb; protected ArrayList<String> favourites; favourites.add("Favourites"); favourites.add("-0.21 + 0.77"); favourites.add("-0.16 + -0.89"); jcb = new JComboBox(favourites.toArray()); This works fine and I can select each option and carry out the selected statements I need to do. However, when I wish to update the JComboBox , it does not update on my GUI. In another method I call: favourites.add("10 + 4"); jcb.revalidate(

How can I add multiple arrays to a JComboBox?

前提是你 提交于 2019-12-11 13:35:22
问题 I am making a theatre seat bookings system for some coursework but am having trouble on creating a JComboBox to help the user select a seat from the set of 197 that there are altogether. The seats are represented by "Seat" objects which are merely a collection of a few variables such as "isBooked" (Boolean). The seats are arranged into multiple seat arrays, each array represents a row of seats e.g. A[], B[]... For the booking of the seats, having the seats separated by row was necessary as

How to reset the JComboBox in JTable to the first value of the JComboBox

一个人想着一个人 提交于 2019-12-11 13:34:42
问题 I'm working on a code in Java Swing. I have created a JComboBox in JTable. It's working :). But once I select a value and click on the save or cancel button, it has to reset to the default value (1st value in the combo box). I tried a lot of ways like combobox.setSelectedIndex(0) . This isn't working. Code: String[] manTimeHr = { "00","01", "02", "03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"}; String[] manTimeMin = {"00","01", "02",

Adding items dynamically to JComboBox

末鹿安然 提交于 2019-12-11 13:10:49
问题 I have to read values from the database and add it to a jcombo box. Names of projects are read from the employee table and stored to a string arraylist. These values are then added to a string array named pro_string. I tried printing the values inside this string array and it works fine. But the values just don't seem to enter into the combobox(combo_project). Following is the code that i have used. It keeps throwing an exception "3". Please help. public class meeting_form extends javax.swing

Add an object to a JComboBox but show a string without overriding the object's .toString() method

感情迁移 提交于 2019-12-11 12:12:07
问题 The object class that I am working with already has its .toString() method overridden, giving its name. But I am using same object in a JComboBox and I need to display another String. Is there a way to accomplish this? 回答1: You bet there is! What you want to do is to give your JComboBox a custom cell renderer. To do this, you could extending DefaultListCellRenderer making sure to override its getListCellRendererComponent(...) method. Once you've done this, you would call setRenderer(...) on

Editable JCombobox mouseclicked event not working

若如初见. 提交于 2019-12-11 11:29:05
问题 I am now in an awkward situation and so I am here to get some expert advice. I have an Editable JComboBox . I have implement actionPerformed event which just works fine. But I have implement mouseListener which is not working. component = jcbItemType.getEditor().getEditorComponent(); component.addMouseListener(new java.awt.event.MouseListener() { public void mouseClicked(java.awt.event.MouseEvent evt) { jcbItemTypeMouseClicked(evt); } public void mousePressed(java.awt.event.MouseEvent evt) {

JTree Editor not setting variables

不打扰是莪最后的温柔 提交于 2019-12-11 10:14:12
问题 I am trying to use a Renderer in a JTree for a Swing application I am developing, the custom renderer is used only when the tree is a leaf object and is composed of a flow layout. An empty label with an image, a JComboBox and finally a label that contains a String. Initially the Renderer is passed a string value via the getTreeCellRendererComponent() method in HazardRenderer.java it is then set using the setText() method in HazardComboBox.java the editor then takes the selected renderer

JList content that changes depending on the selected JComboBox made ​​in

左心房为你撑大大i 提交于 2019-12-11 10:02:22
问题 I would like to create a GUI in Java that is composed of a JComboBox and JList. The alternatives are selected from the JComboBox {A, B, C}. Depending on the choice made ​​(A, B, or C) are shown in JList different lists. example: if I select A in the JComboBox, JList will show the following strings: A1, A2, A3, A4 if I select B in the JComboBox, JList will show the following strings: B1, B2, B3, B4 if I select C in the JComboBox, JList will show the following strings: C1, C2, C3, C4 How can I

Fill a JComboBox with new values

早过忘川 提交于 2019-12-11 09:59:18
问题 currently I am filling my JComboBox like that: countryBox = new JComboBox(countryList.toArray(new String[countryList.size()])); However, when using my program the countryList changes and I would like to fill my JComboBox differently. I tried to use the action to change my JComboBox: countryBox.addActionListener(new ActionListener() { countryBox = new JComboBox(countryList.toArray(new String[countryList.size()])); } However, it does not change its values. For me it seems that the countryBox is

In Java, Deletion operation is correct, but catch gets executed too

孤街浪徒 提交于 2019-12-11 09:39:09
问题 My concept is that I have to select an item in first combobox. It will add up some items to the second combo box, based on the selection. Once, the second combobox is selected, then some access table data is retrieved. Finally, when I click Delete , the record has to get deleted based on the item present in the two combo box. I get the record correctly deleted. But, my problem is, I'm getting an error dialog(which I used in catch) everytime with a No resultset produced error in the command