jcombobox

Java - Allow using backspace in an editable JComboBox with Substance L&F

♀尐吖头ヾ 提交于 2019-12-12 01:09:06
问题 I am using Substance L&F and I have set a JComboBox to editable so that i can select the value that i want from its popup, or type a new value in its Editor. Typing a new value works fine, but if i want to delete a miss-typed letter from the Combo editor, and i click Backspace to do that it selects the letters in the editor instead of erasing them. Here is a screenshot : I want the Combo editor to work like a JTextField when typing keyboard letters or Backspace or Delete in it, so is there a

Delete highlighting in JComboBox

五迷三道 提交于 2019-12-11 23:26:54
问题 When a JComboBox is just made and added and all the background of the selected item is just normal and white: (ignore the enormous spacing after the text) When I then open the list and hover my cursor over an item, that item get's highlighted, all normal, nothing wrong with it. But the problem now is that the highlighting stays once I've clicked on an item: So my question is: How can I make the highlighting go away? Preferably without doing difficult with packages from the community or

Get Id and data from database and add to JCombobox

£可爱£侵袭症+ 提交于 2019-12-11 22:58:09
问题 I want to get name and id from database and add it to JCombobox . For this i used public void add_Category(JComboBox cmb) { try { String query = "SELECT * FROM categories"; ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String Txtcmb = rs.getString(2).trim(); int idCmb = rs.getInt("id"); Item comboItem = new Item(idCmb, Txtcmb); cmb.addItem(comboitem); //This line add only 1 object in combocox but i have 5 in my database } } catch(Exception e) { } } Item.java public class Item {

Populating a JComboBox dynamically without using associative arrays

蓝咒 提交于 2019-12-11 19:44:29
问题 I have a JComboBox populated with information from a file (XML) and I want a second ComboBox to be populated with information based in the selected item in the first one. My english is a bit rusty so I'll show you an example, this is my XML file: <components> <house id="Kitchen"> <espresso_machine>C</espresso_machine> <coffee_machine>C</coffee_machine> <coffee_pot>C</coffee_pot> <kettle>C</kettle> <toaster>C</toaster> <microwave>C</microwave> <oven>C</oven> <frying_pan>C</frying_pan> <stand

How to change comboBox options depending on the selected item of a different comboBox

时光总嘲笑我的痴心妄想 提交于 2019-12-11 19:35:27
问题 How do I change the options for a combo box depending on the selected item of a different combo box? public class Test extends JFrame{ String[] test = {"blank", "blank_1"}; if (comboBox.getSelectedItem() == "blank"){ String[] test_1 = {"test"}; } else { String[] test_1 = {"test_1"}; } JComboBox comboBox = new JComboBox(test); JComboBox comboBox_1 = new JComboBox(test_1); } 回答1: Here is a simple example to get you started: import java.awt.*; import java.awt.event.*; import java.util.*; import

JComboBox and file read

安稳与你 提交于 2019-12-11 19:14:58
问题 I have login page that controle username and password. I want that when admin is selected in combobox, then program should compare given username and password with first line in my "LoginInformation.txt" file. And when user is selected in combobox and, then program should compare given username and pasword with second line in "LoginInformation.txt" file. But,my code doesn't work correctly! public class LoginFrame extends javax.swing.JFrame { private String username; private char[] Password;

Custom JFileChooser. How to add JComboBox into the JFileChooser

≯℡__Kan透↙ 提交于 2019-12-11 18:39:13
问题 I want to add JComboBox into the JFileChooser. I tried to extend JFileChooser and to add the combo box manually. I actually managed to do it but that removed the file navigation panel from the JFileChooser dialog. Code: public class CustomDefinitionJFileChooser extends JFileChooser{ public CustomDefinitionJFileChooser() { JComboBox comboBox = new JComboBox(); comboBox.setModel(new DefaultComboBoxModel(new String[] { "Item 1", "Item 2" })); super.add(comboBox); } } Expected result: Actual

For one column of a JTable, how do I put a unique combo box editor in each row?

╄→гoц情女王★ 提交于 2019-12-11 16:49:55
问题 Here's the idea: Let's say I have a class extending TableModel , with something like a List<List<String>> collection field. On an event, I want to clear out a JTable and re-add rows where one specific column is a combo box; the items in combo box n are the items in the List<String> from collection.get(n) in my list. So I'm iterating over collection adding rows, and I'm iterating over each collection.get(n) adding combo box items. There are no event listeners. When a separate button is clicked

why this code about combobox doesn't work?

≡放荡痞女 提交于 2019-12-11 16:13:36
问题 I have a combobox which stores "Computer ,Code:21","History ,Code:31" and also the number of items can be changed.but when I write this code for getting its items: List<String> bIHELessons = new ArrayList<String>(); for (int i=0;i<jComboBox1.getItemCount();i++) { String lessons = (String) jComboBox1.getItemAt(i); if (lessons != null&& lessons.trim().length()!=0) { bIHELessons.add(lessons); System.out.println(bIHELessons.toString()); } } it will show these sentences in the console: [Computer

Java - How to make JComboBox of non-String objects display String names?

给你一囗甜甜゛ 提交于 2019-12-11 15:06:33
问题 I would like to make the JComboBox component display String names, rather than references. However, I don't know how that is done. Below shows my codes: public class Properties extends JPanel implements ItemListener { private static final long serialVersionUID = -8555733808183623384L; private static final Dimension SIZE = new Dimension(130, 80); private JComboBox<Category> tileCategory; public Properties() { tileCategory = new JComboBox<Category>(); tileCategory.setPreferredSize(SIZE);