jcombobox

Netbeans - Entering items in a jComboBox

孤街醉人 提交于 2019-12-23 09:26:24
问题 I have generated a GUI from netbeans in which I have placed a combobox too. By default, the items in combobox are item1, item2, item3, item4. But I want my own items. Netbeans doesn't allow editing generated code so how can i edit the comnbobox according to me. Note: I know one method by editing the "model" property of that jComboBox but I don't want to do it like that because I want various items (which are in an array) in that jComboBox so I want to pass that array in that jComboBox like as

Change color of selection (after selection) in a JComboBox

老子叫甜甜 提交于 2019-12-23 02:55:10
问题 I'm writing a GUI using Swing. I have a custom written JComboBox using a ListCellRenderer and a BasicComboBoxEditor . In my getListCellRendererComponent() method I change the color of the the list based on whether the item is "selected" (mouse is hovering above), which is nice and all, but I don't want the selection to change background color once a choice is made, which it currently does. The first picture shows how the interface looks before a selection is made, and the second one shows how

How to prevent JComboBox drop-down list from exceeding vertical screen size

£可爱£侵袭症+ 提交于 2019-12-22 14:59:36
问题 I use a JComboBox with many entries (hundreds). I want to limit the size of its drop-down list to the vertical size of the screen. Using a fixed size does not work out properly for different look&feels and screen resolutions. I am using Java 6u25 on Windows 7. If I set the maximum row count to a value (e.g. 100) that exceeds the number of list items (=rows) that fit on the screen (75), the drop-down list seems to be drawn in full size but the lowest entries are never visible. Here is a

The Stubborn JComboBox

若如初见. 提交于 2019-12-22 08:56:02
问题 I have a JComboBox shown in the code below. When the program starts its actionPerformed event fires up immediately causing some null pointer exceptions so I want to start with none of the elements selected. However, for some reason it does not work (it always start with displaying "USD/TRY" whatever I do). Anyone has any idea ? JComboBox comboBox = new JComboBox(new String[]{"USD/TRY", "EUR/TRY", "GBP/TRY"}); comboBox.setSelectedIndex(-1); // doesnt change anything comboBox.setSelectedIndex(2

JTable, JComboBox using custom Objects

ぃ、小莉子 提交于 2019-12-22 05:14:08
问题 Hi if You put JComboBox in JTable and String[] array to JComboBox everything works fine. Buf if You put your own data type to JComboBox selecting values in same column becomes complicated. Here is official example. Try changing following part: JComboBox comboBox = new JComboBox(); comboBox.addItem("Snowboarding"); comboBox.addItem("Rowing"); comboBox.addItem("Knitting"); comboBox.addItem("Speed reading"); comboBox.addItem("Pool"); comboBox.addItem("None of the above"); sportColumn

JTable, JComboBox using custom Objects

这一生的挚爱 提交于 2019-12-22 05:14:06
问题 Hi if You put JComboBox in JTable and String[] array to JComboBox everything works fine. Buf if You put your own data type to JComboBox selecting values in same column becomes complicated. Here is official example. Try changing following part: JComboBox comboBox = new JComboBox(); comboBox.addItem("Snowboarding"); comboBox.addItem("Rowing"); comboBox.addItem("Knitting"); comboBox.addItem("Speed reading"); comboBox.addItem("Pool"); comboBox.addItem("None of the above"); sportColumn

How to update JComboBox content from ArrayList?

我是研究僧i 提交于 2019-12-22 04:50:51
问题 I have JComboBox based on ArrayList: private ArrayList<String> klienci = new ArrayList<String>(); private JComboBox klienciLista; and I add it in constructor: klienciLista = new JComboBox(klienci.toArray()); klienciLista.setPrototypeDisplayValue("#############################"); panel.add(klienciLista); //JPanel panel At the start List is empty. Client gets via socket new ArrayList in thread: public void run() { try { host = InetAddress.getLocalHost().getHostName(); socket = new Socket(host,

How to let the content in JComboBox display in the center?

依然范特西╮ 提交于 2019-12-21 09:10:41
问题 Currently I have this JComboBox , how can I get to center the content inside it? String[] strs = new String[]{"15158133110", "15158133124", "15158133458"}; JComboBox com = new JComboBox(strs); 回答1: You need to create a Renderer then apply it to the JComboBox DefaultListCellRenderer dlcr = new DefaultListCellRenderer(); dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER); com.setRenderer(dlcr); also import this, import javax.swing.DefaultListCellRenderer; 回答2: ((JLabel)jComboBox1

Checking if an item already exists in a JComboBox?

和自甴很熟 提交于 2019-12-21 03:34:18
问题 Is there an easy way to check if an item already exists in a JComboBox besides iterating through the latter? Here's what I want to do: Item item = ...; boolean exists = false; for (int index = 0; index < myComboBox.getItemCount() && !exists; index++) { if (item.equals(myComboBox.getItemAt(index)) { exists = true; } } if (!exists) { myComboBox.addItem(item); } Thanks! 回答1: Use a DefaultComboBoxModel and call getIndexOf(item) to check if an item already exists. This method will return -1 if the

JComboBox Warning preventing opening the design page in eclipse

痞子三分冷 提交于 2019-12-21 01:57:43
问题 OK i am using eclipse and its GUI editor and i have a string like this: public static String[] blah = {"Blah", "Blah", "Blah", "Blah"}; and a JComboBox like this: JComboBox comboBox = new JComboBox(blah); comboBox.setBounds(10, 56, 312, 37); contentPane.add(comboBox); The combobox uses the string above to get its data but when i enter in "blah" to the combobox it has this error... Type safety: The constructor JComboBox(Object[]) belongs to the raw type JComboBox. References to generic type