jcombobox

Share data source for two comboboxes

自闭症网瘾萝莉.ら 提交于 2019-12-02 10:57:42
问题 I have multiple comboboxes in my GUI which all need to have the data. This data will change at random so a quick way to keep all values synced is needed. I encountered DefaultComboBoxModel which actually fits quite perfect. Only thing is, that I need the comboboxes to be independent of each other - meaning: if I select a value on one, all others shouldn't change. I've done a bit of research and read the standard java tutorials but none tell me really how to achieve this with the

Loading an ArrayList into a JCombobox using netbeans

孤者浪人 提交于 2019-12-02 10:48:05
Currently have an ArrayList called SundayList which is loaded as soon as the frame AddStudent is loaded (bit of GUI) The code automatically generated by Netbeans is: comboboxSunday = new javax.swing.JComboBox(); comboboxSunday.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item1", "Item2" })); How do I load the combobox items with my own array? The array includes items such as: Activity1 Activity2 Activity3 Activity4 From my previous search, people mentioned about using a toString() and toArray() , and I'm not familiar with either methods, and how they help in loading the list

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

杀马特。学长 韩版系。学妹 提交于 2019-12-02 10:47:28
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? First you want to have a text field without focus cycling, and tab suppression: jTextField1.setFocusCycleRoot(true); jTextField1

How to use actionPerformed( ActionEvent e ) with more that one button?

青春壹個敷衍的年華 提交于 2019-12-02 10:03:44
So my assignment says to create a sequential file. My professor gave me this simple code for the actionperformed: public void actionPerformed( ActionEvent e ) { //FOR STATE AND COUNTRY String country = (String)comboBox_1.getSelectedItem(); Object o = states.get( country ); if (o == null) { comboBox_2.setModel( new DefaultComboBoxModel() ); } else { comboBox_2.setModel( new DefaultComboBoxModel( (String[])o ) ); } //****DONE WITH THE STATE AND COUNTRY COMBOBOXEZ***** addRecord( ) ; if ( e.getSource( ) == btnDone ) { try { output.close( ); } catch ( IOException io ) { System.err.println( "File

assign keys for combo box in java

家住魔仙堡 提交于 2019-12-02 09:26:50
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? You can add an item as an object instead of adding String like this: JComboBox<ItemClass> jc = new JComboBox<ItemClass>(); jc.addItem(item1); jc.addItem(item2); jc.addItem(item3); So to return key,

Using the ComboBoxEditor interface with Custom JComponent, and allow edit, and display the List

我们两清 提交于 2019-12-02 09:10:43
I was checking the documentation. https://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html https://alvinalexander.com/java/jwarehouse/openjdk-8/jdk/src/share/classes/javax/swing/plaf/basic/BasicComboBoxEditor.java.shtml http://www.java2s.com/Tutorials/Java/javax.swing/ComboBoxEditor/Java_ComboBoxEditor_getEditorComponent_.htm ... and I'm trying to use my Custom ComboBox implementing the interface ComboBoxEditor . Here my complete Code... I hava one JPanel with JComponents ... class ThePanel extends JPanel { private Font intFont = new Font("Monospaced", Font.PLAIN, 8); private

JComboBox shared between multiple table cells automatically selecting currently selected item

本小妞迷上赌 提交于 2019-12-02 07:58:05
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 the last selected item. As a quick demonstration I simply modified the code from above to show the issue

JTree selection issue

☆樱花仙子☆ 提交于 2019-12-02 07:40:20
问题 I've got a JTree with nodes made up of a JLabel and a JComboBox. What I want is that when clicked on, the selected JComboBox will expand, but it seems like the first click is being consumed by the JTree itself (?), so I have to click it twice. Here is the code I have: import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.UIManager.LookAndFeelInfo; import javax.swing.plaf.ColorUIResource; import javax.swing.tree.*; public class JComboBoxJTree

Having several JComboBoxes with different values in a JTable

别等时光非礼了梦想. 提交于 2019-12-02 07:09:22
问题 I want to create a JTable where in a specific column named "Tools" a JComboBox should be accommodated. the values of the JComboBox should differ for each row. In the constructor I have the following piece of code: public Table(List<Software> software_list) throws TransformerFactoryConfigurationError, TransformerException, Exception { //****** create an 2D array object containing the emulators list data to be sent to the table model ****** software_list_to_array = new Object[software_list.size

JComboBox only show one item from database

♀尐吖头ヾ 提交于 2019-12-02 05:51:41
问题 I'm trying to display database item into a JComboBox and this is my code. public static void checkItemName(){ Connection conn = SQLite.SQLite(); String sql = "select itemname from item"; try{ Statement statement = conn.createStatement(); ResultSet resultSet = statement.executeQuery(sql); while (resultSet.next()){ String list = resultSet.getString("itemname"); purcItemName.addItem(list); conn.close(); } } catch (SQLException lol){ System.out.println(lol.toString()); } } I did declare static