Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-23-2008, 07:21 AM
Member
 
Join Date: May 2008
Posts: 21
crazydeo is on a distinguished road
[SOLVED] 2 D Array and JComboBox on a JPanel
I don't know if I will be able to explain this well, but here it goes.

I havea 2 dimensional array with values in a Jpanel and I want to use a combobox instead of a JList to show the values in the array.

For example:
user chooses auto part number in combobox
3 textfields are updated with corresponding part numbers for generic brands.

Hopefully some one can help me out!!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-23-2008, 07:39 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You try to get the array name on combo box, and corresponding values want to display on text fields. Is that right?
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-23-2008, 09:43 AM
Member
 
Join Date: May 2008
Posts: 21
crazydeo is on a distinguished road
No, actually I have the ComboBox that is is being filled by the values from the array but I need the textfields to populate from the array as well and then correspond with the ComboBox.... When I pick a different value in the ComboBox the textfields should auto populate with the new values.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-23-2008, 09:58 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Ok, why it's difficult. At the state change of the combobox, get the selected text. Using that I think you can find values which wants to add into text fields. Set text on text fields then.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-23-2008, 10:20 AM
Member
 
Join Date: May 2008
Posts: 21
crazydeo is on a distinguished road
Code:
public void itemStateChanged(ItemEvent evt) { plainWrapComboBox.???
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-23-2008, 10:29 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Code:
getSelectedItem();
Return an object there. You can cast it into string.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-23-2008, 10:57 AM
Member
 
Join Date: May 2008
Posts: 21
crazydeo is on a distinguished road
I think i'm lost

Code:
import java.text.*; import javax.swing.*; import java.awt.event.*; public class PlainWrapParts extends JFrame implements ItemListener, ActionListener { //create the main panel, radio buttons, and text fields for the panel JPanel mainPanel = new JPanel(); String[][] partNumberString = { {"PR214", "MR43T", "RBL8", "14K22"}, {"PR223", "R43", "RJ6", "14K24"}, {"PR224", "R43N", "RN4", "14K30"}, {"PR246", "R46N", "RN8", "14K32"}, {"PR247", "R46TS", "RBL17Y", "14K33"}, {"PR248", "R46TX", "RBL12-6", "14K35"}, {"PR324", "S46", "J11", "14K38"}, {"PR326", "SR46E", "XEJ8", "14K40"}, {"PR444", "47L", "H12", "14K44"} }; String [] brandString = {"Plain Wrap", "Brand A", "Brand C", "Brand X"}; int counterInteger = 0; int plainWrapInteger [] = new int [14]; String plainWrapString, brandAString, brandCString, brandXString, nameString; JComboBox plainWrapComboBox = new JComboBox(partNumberString[0]); JTextField brandATextField = new JTextField(5); JTextField brandCTextField = new JTextField(5); JTextField brandXTextField = new JTextField(5); JButton clearButton = new JButton("Clear Items"); JButton summaryButton = new JButton("Summary of Sales"); JTextField plainWrapAddTextField = new JTextField(5); JTextField brandAAddTextField = new JTextField(5); JTextField brandCAddTextField = new JTextField(5); JTextField brandXAddTextField = new JTextField(5); JButton addButton = new JButton("Add an item"); JTextArea outputTextArea = new JTextArea(20,30); JScrollPane mainScrollPane = new JScrollPane(outputTextArea); public static void main(String[] args) { // Create an object of the class PlainWrapParts myPartsStore = new PlainWrapParts(); myPartsStore.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public PlainWrapParts() { //setting title, size of the designFrame designFrame(); add(mainPanel); setTitle("Plain Wrap Auto"); setSize(500,600); setVisible(true); } public void designFrame() { //add items to the panels mainPanel.add(new JLabel("Plain Wrap")); mainPanel.add(plainWrapComboBox); mainPanel.add(new JLabel("Brand A")); mainPanel.add(brandATextField); mainPanel.add(new JLabel("Brand C")); mainPanel.add(brandCTextField); mainPanel.add(new JLabel("Brand X")); mainPanel.add(brandXTextField); mainPanel.add(new JLabel("Plain Wrap")); mainPanel.add(plainWrapAddTextField); mainPanel.add(new JLabel("Brand A")); mainPanel.add(brandAAddTextField); mainPanel.add(new JLabel("Brand C")); mainPanel.add(brandCAddTextField); mainPanel.add(new JLabel("Brand X")); mainPanel.add(brandXAddTextField); mainPanel.add(addButton); mainPanel.add(clearButton); mainPanel.add(mainScrollPane); brandXTextField.addActionListener(this); brandXAddTextField.addActionListener(this); plainWrapComboBox.addItemListener(this); clearButton.addActionListener(this); addButton.addActionListener(this); } //Different actions performed when the buttons are pushed public void itemStateChanged(ItemEvent evt) { String partNumberString = plainWrapComboBox.getSelectedItem(); plainWrapTextField = } public void actionPerformed(ActionEvent evt) { Object sourceObject = evt.getSource(); //if purchase button pushed everything sent to total class for calculation if(sourceObject == addButton) { getInput(); add(); } //if clear button pushed everything thing is cleared else if(sourceObject == clearButton) { clear(); } } public void getInput() { //validate entry try { if((!(plainWrapAddTextField.getText()).equals(""))) { nameString = plainWrapAddTextField.getText(); if((!(brandAAddTextField.getText()).equals(""))) { nameString = brandAAddTextField.getText(); if((!(brandCAddTextField.getText()).equals(""))) { nameString = brandCAddTextField.getText(); if((!(brandXAddTextField.getText()).equals(""))) { nameString = brandXAddTextField.getText(); try { add(); } catch (NullPointerException e) { JOptionPane.showMessageDialog(null, "invalid"); brandATextField.selectAll(); brandATextField.requestFocus(); } } else { JOptionPane.showMessageDialog(null, "Enter Brand X"); brandXAddTextField.selectAll(); brandXAddTextField.requestFocus(); }} else { JOptionPane.showMessageDialog(null, "Enter Brand C"); brandCAddTextField.selectAll(); brandCAddTextField.requestFocus(); }} else { JOptionPane.showMessageDialog(null, "Enter Brand A"); brandAAddTextField.selectAll(); brandAAddTextField.requestFocus(); } } else { JOptionPane.showMessageDialog(null, "Enter Plain Wrap"); plainWrapAddTextField.selectAll(); plainWrapAddTextField.requestFocus(); } } catch(NullPointerException e) { JOptionPane.showMessageDialog(null, "invalid"); brandATextField.selectAll(); brandATextField.requestFocus(); } } public void add() { boolean done = false; int arrayCount = plainWrapComboBox.getItemCount() - 1; for (int i = 0; i <= arrayCount; i++) if(plainWrapString.equals(partNumberString[0][i])) { done = true; break; } if(done) { JOptionPane.showMessageDialog(null, "Duplicate part number!"); } else if(plainWrapString.length() != 0 && brandAString.length() != 0 && brandCString.length() != 0 && brandXString.length() != 0) { plainWrapAddTextField.setText(plainWrapString); brandAAddTextField.setText(brandAString); brandCAddTextField.setText(brandCString); brandXAddTextField.setText(brandXString); } } public boolean checkInput(String userInputString) { boolean foundBoolean = false; int indexInteger = 0; String inputString = new String(); while(!foundBoolean && indexInteger < plainWrapComboBox.getItemCount()) { inputString = (String) plainWrapComboBox.getItemAt(indexInteger); if(userInputString.equalsIgnoreCase(inputString)) { foundBoolean = true; } else { indexInteger++; } } return foundBoolean; } public void displayPlainWrapFound(boolean partsBoolean, String inputString) { if(partsBoolean) { JOptionPane.showMessageDialog(null,"This part is already in the list"); plainWrapAddTextField.selectAll(); plainWrapAddTextField.requestFocus(); } else { plainWrapComboBox.addItem(inputString); JOptionPane.showMessageDialog(null,"This part is added to the list"); plainWrapAddTextField.setText(""); } } public void clear() { plainWrapAddTextField.setText(""); brandAAddTextField.setText(""); brandCAddTextField.setText(""); brandXAddTextField.setText(""); outputTextArea.setText(""); plainWrapComboBox.requestFocus(); } }
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-23-2008, 11:17 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,376
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
My friend I told this.

getSelectedItem() return an object. So you have to think about that. Like this, much simple.

Code:
//Different actions performed when the buttons are pushed public void itemStateChanged(ItemEvent evt) { String ss = (String) plainWrapComboBox.getSelectedItem(); //String partNumberString = plainWrapComboBox.getSelectedItem(); //plainWrapTextField = }
Try and let me know what happened.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a Table Row with JPanel Composed of JTextField and JComboBox Selectable datechie AWT / Swing 2 07-30-2008 02:33 PM
Adding items to a jComboBox tronovan New To Java 0 08-08-2007 10:48 AM
JComboBox setDisabledTextColor Jack AWT / Swing 2 07-02-2007 07:32 AM
Help with jComboBox Marcus AWT / Swing 2 07-02-2007 01:08 AM
jcombobox Freddie AWT / Swing 4 05-11-2007 02:48 AM


All times are GMT +3. The time now is 06:35 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org