jcombobox

populate JTable with the value selected in Jcombobox

可紊 提交于 2019-12-20 07:46:03
问题 I have a JCombobox and JTable and database jcombobox is filled with the value of first_name of student table from databse. Whenever I select a name from database I want the value of Course name from course and student_score from score table of the database to be displayed in Jtable. Basically I want to display the records of selected in JComboBox in Jtable import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border

In Swing, Enter Key not working in selecting an element from a combobox

浪子不回头ぞ 提交于 2019-12-20 07:33:54
问题 I have added an ItemListener to a JComboBox. The ItemListener is able to detect any selection I make using Mouse click or space-bar. But it is not recognizing the Enter Key. In other words, if I use arrow key to scroll through entries in ComboBox and then hit Enter, then the itemStateChanged method is not invoked. Do you have any ideas? 回答1: for listening of changes from MouseEvent is there ItemListener , firing SELECTED/DESELECTED for listening of ENTER key pressed is there ActionListener

assign keys for combo box in java

穿精又带淫゛_ 提交于 2019-12-20 06:41:55
问题 I want to add a JComboBox in Swing that is simple but I want to assign the values for each items in combo. I have the following code JComboBox jc1= new JComboBox(); jc1.addItem("a"); jc1.addItem("b"); jc1.addItem("c"); Now what I want is that when click on combo box it should return 1, 2 and 3 correspondingly instead of a ,b, c. Is there any way to assign the key values for each items in combo box? 回答1: You can add an item as an object instead of adding String like this: JComboBox<ItemClass>

Windows application with Auto-complete using tab of unix machine files and directories

只愿长相守 提交于 2019-12-20 05:58:42
问题 Unix / Linux support auto-complete of files and directories when pressing "tab". I need to create this ability in my windows application. I have a text field for user input of file name, which I want to respond to a "tab" press like it will do when we're in a unix console: If there is one option - Auto-complete. Some options - show a list of the options. No options - nada. For my SSH connection to my unix machine I use the ch.ethz.ssh API. Is there a way to do so? 回答1: First you want to have

JCombobox Listener how to enable it when item is selected?

折月煮酒 提交于 2019-12-20 05:49:39
问题 I have a JComboBox that displays Name From database Patients_Details public void ComboItem() { chooser.removeAllItems(); chooser.addItem("Please Select..."); try { String sql="select * from Patients_Details"; pst = conn.prepareStatement(sql); rs=pst.executeQuery(); while (rs.next()) { String id = rs.getString("Patient_ID"); // Get the Id String name = rs.getString("Name"); // Get the Name ComboItem comboItem = new ComboItem(id, name); // Create a new ComboItem chooser.addItem(comboItem); //

Change/Update JTable content with JComboBox(category)

孤者浪人 提交于 2019-12-20 04:51:27
问题 I have a problem with my JTable. My JTable displays content of a database. One database table has the name category. Every category is displayed in the JComboBox. If I click on a category it should update the table content. Here is a short snipped of my code for you, so it is easier to help me. The code should be runable: (TestClass - Main) package test; import java.awt.BorderLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import

Alter JComboBox popup size without disturbing Look and Feel?

别等时光非礼了梦想. 提交于 2019-12-20 03:54:09
问题 I'm looking for a way to alter the width of a JComboBox's popup. Basically, the popup should be as wide as the widest combobox entry requires, not as wide as the combobox currently is. The only way I know how to achieve this is creating a custom instance of ComboBoxUI and set that on the JComboBox (Example code demonstrates the goal: Top Combobox shows wide popup, Bottom is the default behavior). However since this replaces the UI of the ComboBox, it may look odd on some L&F's (For example

FocusListener on editable JCombobox not firing

心不动则不痛 提交于 2019-12-20 03:46:40
问题 First of all: Sorry that I cannot provide a SSCCE. I tried to recreate this problem on a small project, but without success, or should I say with success, because its working there! So here is my Problem: I have an editable JCombobox, which should listen to a focus event by clicking in the editor component. But it doesn´t. Here is a code snippet where I attach the listener: cmbZoom.setToolTipText(locale.getString("GUI_ZoomFactor")); cmbZoom.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 16));

Java JComboBox listen a change selection event [duplicate]

Deadly 提交于 2019-12-20 03:19:40
问题 This question already has answers here : JComboBox Selection Change Listener? (6 answers) Closed 6 years ago . I'm trying to listen to a change of selection in a Java JComboBox. I have tried to use an ActionListener but the problem is this: the action listener does something like this public void actionPerformed(ActionEvent e){ JComboBox<String> source = ((JComboBox<String>)e.getSource()); String selected = source.getItemAt(source.getSelectedIndex()); /*now I compare if the selected string is

Fast replacement for JComboBox / BasicComboBoxUI?

穿精又带淫゛_ 提交于 2019-12-20 03:15:18
问题 I've got a JComboBox that potentially can have thousands of items. They're sorted, and there's find-as-you-type, so in principle it's not completely unusable. In practice, it's pretty unusable with just a couple of hundred items. I managed to improve the initial display performance using setPrototypeDisplayValue() , but BasicListUI still insists on configuring the list cell renderer for every item in the box (see BasicListUI.updateLayoutState() ). This, or something like it, is apparently a