Search Results

Search found 59 results on 3 pages for 'jcombobox'.

Page 1/3 | 1 2 3  | Next Page >

  • Putting JComboBox into JTable

    - by Dan
    Hi, I want to put individual JComboBoxes into each cells of a JTable. ie. The JComboBox content is not identical for each cell. I basically would like to be able to just call the following code to add a row of JComboBox into the JTable. Anyone has any idea? Thanks JComboBox cb1 = new JComboBox(...); JComboBox cb2 = new JComboBox(...); model.addRow(new Object[] {"Row name", cb1, cb2} ); JComboBox cb3 = new JComboBox(...); JComboBox cb4 = new JComboBox(...); model.addRow(new Object[] {"Row name 2", cb3, cb4} ); This is the resultant view if I do the above. http://www.freeimagehosting.net/uploads/a6292e08ee.png The closest example code I can find is as follows. But it is for where JComboBox content is identical for the individual column. Not the solution I need. TableColumn col = table.getColumnModel().getColumn(vColIndex); col.setCellEditor(new MyComboBoxEditor(values)); where public class MyComboBoxEditor extends DefaultCellEditor { public MyComboBoxEditor(String[] items) { super(new JComboBox(items)); } }

    Read the article

  • JTextField vs JComboBox behaviour in JTable

    - by Ash
    Okay, this is a hard one to explain but I'll try my best. I have a JTextField and a JComboBox in a JTable, whose getCellEditor method has been overriden as follows: public TableCellEditor getCellEditor( int row, int column ) { if ( column == 3 ) { // m_table is the JTable if ( m_table.getSelectedRowCount() == 1 ) { JComboBox choices = new JComboBox(); choices.setEditable( true ); choices.addItem( new String( "item 1" ) ); return new DefaultCellEditor( choices ); } return super.getCellEditor( row, column ); } Here are the behavioral differences (NOTE that from this point on, when I say JTextField or JComboBox, I mean the CELL in the JTable containing either component): When I click once on a JTextField, the cell is highlighted. Double clicking brings up the caret and I can input text. Whereas, with a JComboBox, single clicking brings up the caret to input text, as well as the combo drop down button. When I tab or use the arrow keys to navigate to a JTextField and then start typing, the characters I type automatically get entered into the cell. Whereas, when I navigate to a JComboBox the same way and then start typing, nothing happens apart from the combo drop down button appearing. None of the characters I type get entered unless I hit F2 first. So here's my question: What do I need to do have JComboBoxes behave exactly like JTextFields in the two instances described above? Please do not ask why I'm doing what I'm doing or suggest alternatives (it's the way it is and I need to do it this way) and yes, I've read the API for all components in question....the problem is, it's a swing API. Thanks in advance, Ash

    Read the article

  • how to show integer values in JComboBox?

    - by Edan
    Hello, I would like to know how to set a JComboBox that contain integers values that I could save. Here is the definitions of values: public class Item { private String itemDesc; private int itemType; public static int ENTREE=0; public static int MAIN_MEAL=1; public static int DESSERT=2; public static int DRINK=3; private float price; int[] itemTypeArray = { ENTREE, MAIN_MEAL, DESSERT, DRINK }; Object[][] data = {{itemDesc, new Integer(itemType), new Float(price)}}; . . . } Now, I want the add a JComboBox that the user will choose 1 of the items (ENTREE, MAIN_MEAL...) and then I could set the number as an Integer. I know that JComboBox need to be something like that: JComboBox combo = new JComboBox(itemTypeArray.values()); JOptionPane.showMessageDialog( null, combo,"Please Enter Item Type", `JOptionPane.QUESTION_MESSAGE);` What am I doing wrong?

    Read the article

  • What is the point of JComboBox's getSelectedItem()?

    - by Chris Cooper
    I just read the JavaDoc for JComboBox (I promise I have a life... I wasn't reading through for fun. =P), and I think the problems I'm having with my program can be attributed to the getSelectedItem() method. The documentation says: Returns the current selected item. If the combo box is editable, then this value may not have been added to the combo box with addItem, insertItemAt or the data constructors. If you can't get values that were added with those methods or with the constructor, of what use is the method? And how can I get the value from an "editable" JComboBox? Link to JavaDoc: http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JComboBox.html#getSelectedItem()

    Read the article

  • How to use Map element as text of a JComboBox

    - by llm
    I am populating a JComboBox (using addItem()) with all the elements of a collection. Each element in the collection is a HashMap (so its a ComboBox of Hashmaps..). My question is - Given that I need each item to be a HashMap how do I set the text to apear in the combobox on the GUI? It needs to be the value of a certain key in the map. Normally if I am populating a combobox with my own type, I would just overide the toString() method...but I am not sure how to acheive this since I am using a Java HashMap. Any ideas (if possible, without implementing my own HashMap)? Update: It seems like there isn't anyway to avoid having the object int the JComboBox overide toString() if I want custom functionality..I wish there was a way to (1) specify the objects to be loaded into the JComboBox and (2) specify how these objects are to appear in the GUI.

    Read the article

  • Implementing a recently used or favorites dropdown in JComboBox

    - by Kevin Day
    I am looking for code that will add favorites / MRU type behavior to a JComboBox. I could code this myself, but it sure seems like someone else has probably already done it. I found the following (which looks exactly like what I want, but the source code is nowhere near complete): http://java.sys-con.com/node/36658 Any suggestions? I need to keep this relatively light, so I'd prefer to not use a component that's part of a monolithic widget library, and open source is preferred.

    Read the article

  • Disabling JComboBox and retaining original item list

    - by n002213f
    My action listener on a JComboBox invokes a thread. I would like the component to be disabled until the thread completes. I have tried calling seEnabled(false) when the thread start and setEnabled(true) when it completes. Unfortunately setEnabled(false) clears the combo box list as well. Is there a way of disabling the component but retain the original list?

    Read the article

  • how to use JComboBox using Enum in Dialog Box

    - by Edan
    Hi, I define enums: enum itemType {First, Second, Third}; public class Item { private itemType enmItemType; ... } How do I use it inside Dialog box using JComboBox? Means, inside the dialog box, the user will have combo box with (First, Second, Third). Also, is it better to use some sort of ID to each numerator? (Integer) thanks.

    Read the article

  • How can I change the arrow style in a JComboBox

    - by Stephane Grenier
    Let's say I want to use a custom image for the arrow in JComboBox, how can I do this? I understand it's possible using the synth xml files, or maybe even UIManager.put(...), but I don't know how. All I want to do at this time is change the arrow image to something else, either programatically or even just overriding the image it uses. How exactly can I do this?

    Read the article

  • my jComboBox does not react to my keyListener and actionPerform perfroms weired stuff

    - by aladdin
    hi I am trying to search for UserName and return values onto jComboBox, here is the code public void actionPerformed(java.awt.event.ActionEvent e) { sr = new Search(((String) jComboBoxReceiver.getSelectedItem())); usrList = sr.searchUser(); String[] userList = new String[usrList.size()] ; for(int i=0;i<usrList.size();i++){ userList[i]= usrList.get(i).getUserName(); } model = new DefaultComboBoxModel(userList); jComboBoxReceiver.setModel(model); } However, if i do that, it does perform correctly, however, it will go search for the first item again, which is very confusing... then i tried using key Pressed if(e.getKeyCode()==13){ sr = new Search(((String) jComboBoxReceiver.getSelectedItem())); usrList = sr.searchUser(); String[] userList = new String[usrList.size()] ; for(int i=0;i<usrList.size();i++){ userList[i]= usrList.get(i).getUserName(); } model = new DefaultComboBoxModel(userList); jComboBoxReceiver.setModel(model); } And this one does not react at all ...

    Read the article

  • How to keep the popup menu of a JComboBox open on populating it ?

    - by Stormshadow
    I have a JComboBox on my Panel. One of the popup menu items is 'More' and when I click that I fetch more menu items and add them to the existing list. After this, I wish to keep the popup menu open so that the user realizes that more items have been fetched however, the popup closes. The event handler code I am using is as follows public void actionPerformed(ActionEvent e) { if (e.getSource() == myCombo) { JComboBox selectedBox = (JComboBox) e.getSource(); String item = (String) selectedBox.getSelectedItem(); if (item.toLowerCase().equals("more")) { fetchItems(selectedBox); } selectedBox.showPopup(); selectedBox.setPopupVisible(true); } } private void fetchItems(JComboBox box) { box.removeAllItems(); /* code to fetch items and store them in the Set<String> items */ for (String s : items) { box.addItem(s); } } I do not understand why the showPopup() and setPopupVisible() methods are not functioning as expected.

    Read the article

  • JCombobox containing enum values inside a table

    - by Edan
    Hello, I have a class containing Enum with values. (names) In other class I would like to enter inside a table a cell type of JCombobox that will use these enums values. my problem is to combain between string values and the enum. for example the enum class: enum item_Type {entree, main_Meal, Dessert, Drink} for example the table class: setTitle("Add new item" ); setSize(300, 80); setBackground( Color.gray ); // Create a panel to hold all other components topPanel = new JPanel(); topPanel.setLayout( new BorderLayout() ); getContentPane().add( topPanel ); //new JComboBox(item_Type.values()); JComboBox aaa = new JComboBox(); aaa = new JComboBox(item_Type.values()); TableColumn sportColumn = table.getColumnModel().getColumn(2); // Create columns names String columnNames[] = {"Item Description", "Item Type", "Item Price"}; // Create some data String dataValues[][] = {{ "0", aaa, "0" }}; // Create a new table instance table = new JTable( dataValues, columnNames ); // Add the table to a scrolling pane scrollPane = new JScrollPane( table ); topPanel.add( scrollPane, BorderLayout.CENTER ); I know that at the dataValues array I cant use aaa (the enum jcombobox). How can I do that? thanks in advance.

    Read the article

  • How to set JComboBox not to select an element when created? (Java)

    - by Alex Cheng
    Hi all. Problem: I am using JComboBox, and tried using setSelectionIndex(-1) in my code (this code is placed in caretInvoke()) suggestionComboBox.removeAllItems(); for (int i = 0; i < suggestions.length; i++) { suggestionComboBox.addItem(suggestions[i]); } suggestionComboBox.setSelectedIndex(-1); suggestionComboBox.setEnabled(true); This is the initial setting when it was added to a pane: suggestionComboBox = new JComboBox(); suggestionComboBox.setEditable(false); suggestionComboBox.setPreferredSize(new Dimension(25, 25)); suggestionComboBox.addActionListener(new SuggestionComboBoxListener()); When the caretInvoke triggers the ComboBox initialisation, even before the user selects an element, the actionPerformed is already triggered (I tried a JOptionPane here): First popup (notice that "flow byte_jump" is selected): Second popup (I think the setSelectionIndex is executed) Then in the end: The problem is: My program autoinserts the selected text when the user selects an element from the ComboBox. So without the user selecting anything, it is automatically inserted already. How can I overcome the problem in this situation? Thanks.

    Read the article

  • JComboBox to string

    - by gabrielle fregil
    I have a String array of names, and then I added it into an editable JComboBox. The user can either pick his/her name from the choices or just input his/her name if not in the choices. How do I put the user input into a new string variable? String [] chooseName = { Mark, John, Allison, Jessica }; JComboBox combo = new JComboBox (chooseName); combo.setEditable(true); String chosenName = /* how do i place what the user inputed here? */

    Read the article

  • How to select item in jComboBox

    - by jtnire
    Hi folks, I have a jComboBox that I am populating with some objects. The objects are of a type which I have made myself, and include a String and an int. The object's toString method returns the String, which is displayed in the Combo Box. Now, I wish to select an item in the Combo Box with code. How do I do this? There are multiple items starting with the same letter Thanks

    Read the article

  • How to listen to JComboBox's width changes?

    - by agnieszka
    I tried PropertyChangeListener with property set to "width", "Width", "size" and "Size". PropertyChangeListener widthChangeListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { //code } }; streamsComboBox.addPropertyChangeListener("width", widthChangeListener); projectsComboBox.addPropertyChangeListener("width", widthChangeListener); vobsComboBox.addPropertyChangeListener("width", widthChangeListener); Nothing works - the handler method is never fired. What should I do to handle JComboBox's size change? Where does the property name come from anyway?

    Read the article

  • Java Swing: How to make the JComboxBox drop down list taller?

    - by NoozNooz42
    How to make the "dropdown" (or "popup", I don't know how it's called) of a JComboBox taller on the screen? By default, when I open my JComboBox I see, say, 7 out of 29 items, then I need to scroll. What should I do so that I can see, say, 15 out of these 32 items? (or if the dropdown is, say, 150 pixels tall, how can I make it 300 pixels tall?) I've read the Sun tutorial on JComboBox and the JavaDoc but I must have overlooked the method(s) to call.

    Read the article

  • assign keys for combo box in java

    - by adesh kumar
    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?

    Read the article

  • populatin jComBobox with data from a db tbl(table) column

    - by mnmyles
    Hi guyz? I have a JComboBox which i have named "venue_JCB" i want to load details from a tbl column on form load at the initcomponets() i have declared the method "accessDBinit() ;" and after the initComponets() i have implemented the accessDBinit(); method as follows: ================================code============================ void accessDBinit() //Get Student List in the List Box { try { sql = "SELECT classLevel FROM class_session ORDER BY classLevel"; java.lang.Class.forName("com.mysql.jdbc.Driver"); Connection con2=DriverManager.getConnection("jdbc:mysql:///coast","root",""); Statement stmt2 = (Statement)con2.createStatement(); boolean hasResults = stmt2.execute(sql); if(hasResults) { ResultSet rs2 = stmt2.getResultSet(); if(rs2!=null) { displayResultsinit(rs2); } db.stmt.close(); } } catch(Exception e) { System.out.println(e+"Error in connection"); } } void displayResultsinit(ResultSet r) throws SQLException { ResultSetMetaData rmeta = r.getMetaData(); int numColumns=rmeta.getColumnCount(); while(r.next()) { for(int i=1;i<=numColumns;++i) { if(i<=numColumns) { venue_JCB.addItem(r.getString(i)); } } } } ====================================end of code=================================== the method works (Populate the combobox) but at the output bar i get the following on form load and also whenever i select a component from the combobox ======= error===== java.lang.NullPointerExceptionError in connection could some one please tell me where i am going wrong with the method? Thanks in advance regards Malachi

    Read the article

  • How to check and match the possible combinations of arraylist elements

    - by Jessy
    String [] A = {"High","Medium","Low"}; String [] B = {"High","Medium","Low"}; String [] C = {"High","Medium","Low"}; String [] D = {"High","Medium","Low"}; String [] E = {"High","Medium","Low"}; String [] F = {"High","Medium","Low"}; JComboBox Ai = new JComboBox(A); JComboBox Bi = new JComboBox(B); JComboBox Ci = new JComboBox(C); JComboBox Di = new JComboBox(C); JComboBox Ei = new JComboBox(E); JComboBox Fi = new JComboBox(F); .... //add the user choice in arrayList ArrayList<String> a = new ArrayList<String>(); a.add((String) Ai.getSelectedItem()); a.add((String) Bi.getSelectedItem()); a.add((String) Ci.getSelectedItem()); a.add((String) Di.getSelectedItem()); a.add((String) Ei.getSelectedItem()); a.add((String) Fi.getSelectedItem()); Scenario: On each comboBox, user need to choose one, which mean there are 6 choices at the end. There are 6*5*4*3*2*1 = 720 possible combinations of choices made by the user. What is the best way to check and match the user choice without writing the 720 else if ? e.g. if(Ai=="High" && Bi=="High" && Ci=="Low" && Di=="High" && Ei=="Low" && Fi=="Medium") { System.out.println("Good Choice"); } Thank you.

    Read the article

  • can i add the combobox into particular cell of the JTable?

    - by Venkats
    I want to add combobox into a cell of JTable. model=new DefaultTableModel(data,col); JTableHeader head=new JTableHeader(); head.setBackground(Color.BLUE); table=new JTable(model); table.add(head); JComboBox combo = new JComboBox(); combo.addItem("Names"); combo.addItem("Antony"); combo.addItem("Victor"); combo.addItem("Ramkumar"); table.add(combo); But i cant get the combobox in the cell. Is it possible to set combo box?

    Read the article

  • Java - JTable multiple instances

    - by Brian
    I have a JTable that gets data added to it from another JTable. Now I want to switch between JTables according to the day selected in a JComboBox. For example, if I choose Monday I add programs added to it then I select Tuesday from the JComboBox and a fresh JTable appears. If I go to Monday again the programs should still be there (until the program is closed). How do I create multiple JTables (the JTable remains the same) for the days and let the info remain there until program closure? Here is an example to show you what I mean:

    Read the article

  • DYNAMICALLY CHANGE JCOMBOBOX

    - by Suman.hassan95
    i am fetching the data values from the database success fully. I have also stored them into a String array. I need to load the String array as the items of the ComboBox in response to key actionperformed . How can i reload the items of the ComboBox whenever a key is pressed as the fetched values depend on the key pressed. Rather simply, i need to dynamically refresh the ComboBox items. please help.

    Read the article

  • JFrame not working correctly

    - by Nick Gibson
    This is making me very angry, I have worked on this for 2 days, have 2 books open and have looked through them, and STILL can't get this program to run the way I want it run. I'm getting to the point where if this doesn't help, I quit. I want a SIMPLE Frame application. It has a JComboBox centered at the top. Next to it is a text field big enough to show numeric digits such as "$49.99" Below it is a spot for a Text area showing terms of service Below that is the checkbox agreeing to the terms of service Below that is 2 buttons "Accept" and "Decline" I Have worked on this for 2 days, here is the coding: public class Bar extends JFrame implements ActionListener { public Bar(final JFrame frame) { String[] tests = { "A+ Certification", "Network+ Certification", "Security+ Certification", "CIT Full Test Package" }; JButton button = new JButton("Click Meh"); add(new JLabel("Welcome to the CIT Test Program ")); add(new JLabel("Please select which Test Package from the list below.")); frame.setVisible(true); frame.setSize(250,250); JPanel pane1 = new JPanel(new FlowLayout()); JPanel pane2 = new JPanel(new FlowLayout()); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenu editMenu = new JMenu("Edit"); JMenu helpMenu = new JMenu("Help"); menuBar.add(fileMenu); menuBar.add(editMenu); menuBar.add(helpMenu); JMenuItem newMenu = new JMenuItem("New (Ctrl+N)"); JMenuItem openMenu = new JMenuItem("Open (Ctrl+O)"); JMenuItem saveMenu = new JMenuItem("Save (Ctrl+S)"); saveMenu.addActionListener(this); JMenuItem exitMenu = new JMenuItem("Exit (Ctrl+W)"); JMenuItem cutMenu = new JMenuItem("Cut (Ctrl+X)"); JMenuItem copyMenu = new JMenuItem("Copy (Ctrl+C)"); JMenuItem pasteMenu = new JMenuItem("Paste (Ctrl+V)"); JMenuItem infoMenu = new JMenuItem("Help (Ctrl+H)"); fileMenu.add(newMenu); fileMenu.add(openMenu); fileMenu.add(saveMenu); fileMenu.add(exitMenu); editMenu.add(cutMenu); editMenu.add(copyMenu); editMenu.add(pasteMenu); helpMenu.add(infoMenu); frame.setJMenuBar(menuBar); JComboBox packageChoice = new JComboBox(tests); frame.add(packageChoice); } public void actionPerformed(ActionEvent e) { Object source = e.getSource(); { } } EDIT: Forgot to add the second program public class JFrameWithPanel { public static void main(String[] args) { JPanel panel = new Bar(new JFrame("CIT Test Program")); } } How do I get this to have everything where I want it and show up? I'm very confused because of this and now barely even get how Frames work.

    Read the article

1 2 3  | Next Page >