jcombobox

Populate a JComboBox with an int[]

ε祈祈猫儿з 提交于 2020-06-23 16:33:01
问题 Is it possible to populate a JComboBox with an int[]? I am writing a code that will use a JComboBox populated with years (in integers). The code I have written is this: int[] birthYear = new int[currentYear]; //currentYear is an int variable int inc=1; for(int i=0;i<currentYear;i++) { birthYear[i]= inc; inc++; } birthYearBox = new JComboBox(birthYear); //this is the line in which the error occurs I want these to integers in the ComboBox so that I can subtract from them. Do I have to populate

Use one JComboBox to control another Jcombo Box

北战南征 提交于 2020-05-18 07:47:20
问题 I want the value of one JComboBox to change depending upon the value of another JComboBox . in one JComboBox , I am showing designation of doctors, which I retrieve from the database. Depending on that designation I want to show the name of doctors in another JComboBox . all the information is stored in doctor table. 回答1: Add an ActionListener to the first combo box. In the listener you need to reset the ComboBoxModel of the second combo box based on the selected item. Something like: import

JComboBox shared between multiple table cells automatically selecting currently selected item

痴心易碎 提交于 2020-02-16 07:43:30
问题 I have added a combobox as a cell editor using the code provided by camickr below as reference: How to add unique JComboBoxes to a column in a JTable (Java) Except in my case, I only need one combobox to be used by all of the cells within a column. The problem I'm running into is that the combobox automatically selects the last selected item (or current selected item, not sure), and since different rows share the same combobox, if you click on one of the cells, it'll automatically change to

Make a selection in one jcombobox enable a different jcombobox

老子叫甜甜 提交于 2020-02-06 09:24:04
问题 I have 7 jcomboboxes that all start with the same default selection. How do I make then next one enabled when something other than the default if selected in the preceding jcombobox? if ( ! (custData1.equals("Please Select a Customer from the dropdown menu")) ){ custData2.setEnabled(true); if ( ! (custData2.equals("Please Select a Customer from the dropdown menu")) ){ custData3.setEnabled(true); if ( ! (custData3.equals("Please Select a Customer from the dropdown menu")) ){ custData4

typeable JComboBox

一笑奈何 提交于 2020-02-04 04:05:07
问题 I am sure this has been asked but I can't find it (maybe I don't know how to search for it). I have a JComboBox with lots of values, so navigating through all of them is painful. I would like it to change its selection the way browsers do: when you type the first letter, say s , it would select the first element starting with s , then if you quickly type the second letter, say a , the selection would change to the first element starting with sa , and so on. Just a transparent, "typeable"

jcombobox populate with hashmap

ε祈祈猫儿з 提交于 2020-01-30 12:15:11
问题 I want to fill my combobox with a display value and a number value HashMap<Integer, String> databaseList I would to display the string in the combobox but the value of the comboxbox must be integer. I know this is posible in c# is this also possible in Java? 回答1: I want to fill my combobox with a display value and a number value I would create a separate Object to contain the two properties and then add these indivdual objects to the combo box. Check out Combo Box With Hidden Data for an

Java JComboBox Incompatible Types: Cannot be converted to string

孤街浪徒 提交于 2020-01-30 11:52:26
问题 I have this error when i try to add items in the JComboBox incompatible types: ComboBox cannot be converted to String This is my method to load the data from database to the JComboBox... public final void loadProducts() { try { String sql = "SELECT * from product"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { combobox.addItem(new ComboBox(rs.getString(2), rs.getString(1))); } combobox.setSelectedIndex(-1); } catch (SQLException ex) { System.out.println(ex); } }

After updating JComboBox, how to refresh length of box

人盡茶涼 提交于 2020-01-25 20:09:21
问题 I am trying to create a way to update a JComboBox so that when the user enters something into the text field, some code will process the entry and update the JComboBox accordingly.The one issue that I am having is I can update the JComboBox, but the first time it is opened, the box has not refresh the length of the options in it and as seen in the code below it displays extra white space. I do not know if there is a better different way to do this, but this is what I came up with. Thanks for

jcombobox actionperformed event

百般思念 提交于 2020-01-25 10:52:21
问题 i am finding it difficult figuring our how the jcombobox actionperformed event works. I have a form which contains a jcombobox and jtable. Change in jcombobox results in data being updated in the jtable. To implement this, I implemented the actionperformed event for the jcombobox. This code contains certain checks and validations and warnings for users before updating the values in the jtable. The problem I am facing is that when the form loads for the 1st time, the actionperformed event for

How do I customize a JComboBox so that the pop-up is a JTree (instead of a list)?

为君一笑 提交于 2020-01-24 05:28:06
问题 I am trying to create a combo box so that I can put whatever control I prefer within the pop-up, in my specific case a JTree. Having a look at how the JComboBox is implement, the pop-up is really created by the UI delegate. The problem in changing that is that it would need to be re-implemented for each look and feel, which is something I do not want to do... I basically want a component that it has the look and feel of a JComboBox (in the current look and feel) and the popup is a JTree (in