How to Populate GUI Fields from JList

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • no1zson
    New Member
    • Jul 2007
    • 38

    How to Populate GUI Fields from JList

    I am a beginner here, still in my first Java class, so I hope this question is not so simple as to offend anyone, but I am finishing up my cd inventory program.
    Adding some GUI buttons to manipulate data in my JList.
    JList is beyond the scope of my class so I am finding help hard to come by.
    I only have two weeks of class left, so it is too late to go back to my array now.
    It is sink or swim with what I have. :o)

    For my question ... I have an ADD button that works like a charm, populates JList from my fields. I am now working on the PREV button to pull the information back to the fields from the previous cd. I have coded and coded but I am obviously doing something wrong because it keeps erroring upon execution.
    Compiles fine, but will not run. Keep getting:
    Exception in thread "AWT-EventQueue-0" java.lang.Numbe rFormatExceptio n: For input string: ""
    at java.lang.Numbe rFormatExceptio n.forInputStrin g(NumberFormatE xception.java:4 8)
    at java.lang.Integ er.parseInt(Int eger.java:468)
    at java.lang.Integ er.parseInt(Int eger.java:497)
    at Inventory2.btnA ddActionPerform ed(Inventory2.j ava:255)
    at Inventory2.acce ss$000(Inventor y2.java:10)
    at Inventory2$2.ac tionPerformed(I nventory2.java: 155)
    at javax.swing.Abs tractButton.fir eActionPerforme d(AbstractButto n.java:1849)
    at javax.swing.Abs tractButton$Han dler.actionPerf ormed(AbstractB utton.java:2169 )
    at javax.swing.Def aultButtonModel .fireActionPerf ormed(DefaultBu ttonModel.java: 420)
    at javax.swing.Def aultButtonModel .setPressed(Def aultButtonModel .java:258)
    at javax.swing.pla f.basic.BasicBu ttonListener.mo useReleased(Bas icButtonListene r.java:236)
    at java.awt.Compon ent.processMous eEvent(Componen t.java:5517)
    at javax.swing.JCo mponent.process MouseEvent(JCom ponent.java:313 5)
    at java.awt.Compon ent.processEven t(Component.jav a:5282)
    at java.awt.Contai ner.processEven t(Container.jav a:1966)
    at java.awt.Compon ent.dispatchEve ntImpl(Componen t.java:3984)
    at java.awt.Contai ner.dispatchEve ntImpl(Containe r.java:2024)
    at java.awt.Compon ent.dispatchEve nt(Component.ja va:3819)
    at java.awt.Lightw eightDispatcher .retargetMouseE vent(Container. java:4212)
    at java.awt.Lightw eightDispatcher .processMouseEv ent(Container.j ava:3892)
    at java.awt.Lightw eightDispatcher .dispatchEvent( Container.java: 3822)
    at java.awt.Contai ner.dispatchEve ntImpl(Containe r.java:2010)
    at java.awt.Window .dispatchEventI mpl(Window.java :1791)
    at java.awt.Compon ent.dispatchEve nt(Component.ja va:3819)
    at java.awt.EventQ ueue.dispatchEv ent(EventQueue. java:463)
    at java.awt.EventD ispatchThread.p umpOneEventForH ierarchy(EventD ispatchThread.j ava:242)
    at java.awt.EventD ispatchThread.p umpEventsForHie rarchy(EventDis patchThread.jav a:163)
    at java.awt.EventD ispatchThread.p umpEvents(Event DispatchThread. java:157)
    at java.awt.EventD ispatchThread.p umpEvents(Event DispatchThread. java:149)
    at java.awt.EventD ispatchThread.r un(EventDispatc hThread.java:11 0)


    Here is my code. Everything works except the Previous Button action event.
    Any suggestions?

    Code:
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.text.*;
    import java.lang.*;
    
    public class Inventory2 extends JFrame
    {
    	private JLabel cdNameLabel; // name label 
    	private JLabel artistLabel; // item number label 
    	private JLabel nstockLabel; // units in stock label 
    	private JLabel priceLabel; // price each label 
    	private JLabel itemLabel; // item number label 
    	private JTextField cdNameField; // name display 
    	private JTextField artistField; // artist display 
    	private JFormattedTextField nstockField; // units in stock display 
    	private JFormattedTextField priceField; // price each display 
    	private JTextField itemField; // item number display 
    	private NumberFormat nstockFormat; // format field and parse numbers 
    	private NumberFormat priceFormat; // format field and parse numbers 
    	private JButton btnAdd; // first button 
    	private JButton btnPrev; // previous button 
    	private JButton btnNext; // next button 
    	private JButton btnDel; // last button 
    	private JButton btnFirst; // first button
    	private JButton btnLast; // last button
    	private JButton btnModify; // modify button
    	private JButton btnSave; // save button
    	private JButton btnSearch; // search button
    	private JPanel buttonJPanel; // JPanle to hold buttons 
    	private JPanel fieldJPanel; // JPanel to hold labels and displays 
    	private JPanel fontJPanel; // JPanel to display logo 
    	private int currCD; 
    	private double total = 0; // variable for total inventory 
    	private JList Inventorylist; // JList to take place of old array
    	private DefaultListModel listModel;
    	private JScrollPane jScrollPanel;  
    	private float Invtotal = .00f;
    	
    	public Inventory2() // create class and method to perform GUI build 
    	{ 
    		initComponents(); 
    	} 
    
    	private void initComponents() 
    	{ 
    		// create label names 
    		cdNameLabel = new JLabel("CD Name:"); 
    		artistLabel = new JLabel("Artist:");
    		nstockLabel = new JLabel("In Stock:"); 
    		priceLabel = new JLabel("Each Item Cost:$"); 
    		itemLabel = new JLabel("Item Number:"); 
     
    		
    		// initial fields
    		cdNameField = new JTextField(25);
    		cdNameField.setEditable(true);
    		artistField = new JTextField(15);
    		artistField.setEditable(true);
    		nstockField = new JFormattedTextField(nstockFormat);
    		nstockField.setEditable(true);
    		nstockField.setColumns(5);
    		priceField = new JFormattedTextField(priceFormat);
    		priceField.setEditable(true);
    		priceField.setColumns(5);
    		itemField = new JTextField(4);
    		itemField.setEditable(true);
    				
    		// JList
    		jScrollPanel = new JScrollPane();
    		Inventorylist = new JList(); 
    		currCD = 0;
    	
    				
    		// buttons 
    		btnAdd = new JButton(); 
    		btnNext = new JButton(); 
    		btnPrev = new JButton(); 
    		btnDel = new JButton();
    		btnLast = new JButton();
    		btnFirst = new JButton();
    		btnModify = new JButton(); 
    		btnSave = new JButton();
    		btnSearch = new JButton();
    		
    		getContentPane().setLayout(new FlowLayout());
    		
    		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    		
    
    		// place textFields and labels
    		
    		//artist
    		artistLabel.setText("Artist"); 
    		getContentPane().add(artistLabel); 
    
    		artistField.setMinimumSize(new Dimension(70,20)); 
    		artistField.setPreferredSize(new Dimension(70,20));
    		getContentPane().add(artistField); 
    		
    		// cd name
    		cdNameLabel.setText("CD Name"); 
    		getContentPane().add(cdNameLabel); 
    
    		cdNameField.setMinimumSize(new Dimension(70,20)); 
    		cdNameField.setPreferredSize(new Dimension(70,20));
    		getContentPane().add(cdNameField);
    		
    		// copies in stock
    		nstockLabel.setText("Copies In Stock"); 
    		getContentPane().add(nstockLabel); 
    
    		nstockField.setMinimumSize(new Dimension(5,20)); 
    		nstockField.setPreferredSize(new Dimension(5,20));
    		getContentPane().add(nstockField); 
    		
    		//price of cd
    		priceLabel.setText("Price"); 
    		getContentPane().add(priceLabel); 
    
    		priceField.setMinimumSize(new Dimension(20,20)); 
    		priceField.setPreferredSize(new Dimension(20,20));
    		getContentPane().add(priceField); 
    		
    		//item number of cd
    		itemLabel.setText("Item Number"); 
    		getContentPane().add(itemLabel); 
    
    		itemField.setMinimumSize(new Dimension(5,20)); 
    		itemField.setPreferredSize(new Dimension(5,20));
    		getContentPane().add(itemField); 
    		
    
    		// add listeners
    		
    		btnAdd.setText("Add");
    		btnAdd.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnAddActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnAdd);
    		 
    		// PREVIOUS
    		btnPrev.setText("Previous");
    		btnPrev.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnAddActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnPrev);
    		
    		// NEXT
    		btnNext.setText("Next");		btnNext.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnAddActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnNext);
    		
    		// SEARCH
    		btnSearch.setText("Search");
    		btnSearch.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnAddActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnSearch);
    		
    		// FIRST
    		btnFirst.setText("First");
    		btnFirst.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnAddActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnFirst);
    		
    		// LAST
    		btnLast.setText("Last");
    		btnLast.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnAddActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnLast);
    				
    		// MODIFY
    		btnModify.setText("Modify");
    		btnModify.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnAddActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnModify);
    					
    		// SAVE
    		btnSave.setText("Save");
    		btnSave.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnAddActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnSave);
    		
    		// DELETE
    		btnDel.setText("Delete");
    		btnDel.addActionListener(new ActionListener()
    		{
    			public void actionPerformed(ActionEvent evt)
    			{
    				btnAddActionPerformed(evt);
    			}
    		});
    		getContentPane().add(btnDel);
    		
    		
    		// new Jlist model
    		listModel = new DefaultListModel();
    		Inventorylist.setModel(listModel);
    		
    		jScrollPanel.setViewportView(Inventorylist);
    		
    		getContentPane().add(jScrollPanel);
    		
    		pack();
    	}// close
    	
    			
    		private void btnAddActionPerformed(ActionEvent evt)
    		{
    			// Create cd to add
    			CdwArtist newCD = new CdwArtist();
    			newCD.setArtist(artistField.getText());
    			newCD.setName(cdNameField.getText());	
    			newCD.setItemno(Integer.parseInt(itemField.getText()));
    			newCD.setNstock(Integer.parseInt(nstockField.getText()));
    			newCD.setPrice(Float.parseFloat(priceField.getText()));
    			
    			// Add cd to list
    			listModel.addElement(newCD);
    			currCD = listModel.size()-1;  // sets currCD to added index
    			
    			
    			// Clear the text fields after add
    			artistField.setText(null);
    			cdNameField.setText(null);	
    			itemField.setText(null);
    			nstockField.setText(null);
             priceField.setText(null);
    	
    			}// end ADD
    		
    		private void btnPrevActionPerformed(ActionEvent evt)
    		{
    			// Grab Previous cd 
    			CdwArtist newCD = (CdwArtist) listModel.get( currCD-- );
    			newCD.setArtist(artistField.getText());
    			newCD.setName(cdNameField.getText());	
    			newCD.setItemno(Integer.parseInt(itemField.getText()));
    			newCD.setNstock(Integer.parseInt(nstockField.getText()));
    			newCD.setPrice(Float.parseFloat(priceField.getText()));		
    			
    			}// end PREV
    			
    		// run it
    		public static void main(String args[])
    		{
    		java.awt.EventQueue.invokeLater(new Runnable()
    			{
    			public void run()
    				{
    				new Inventory2().setVisible(true);
    			   }
    			});
    		}
    			
    } // close class
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    According to that stacktrace the problem occurs in one of these lines:

    [code=java]
    newCD.setItemno (Integer.parseI nt(itemField.ge tText()));
    newCD.setNstock (Integer.parseI nt(nstockField. getText()));
    [/code]

    This indicates that either the itemField or the nstockFied don't contain a valid
    integer number. As far as I can see those fields are JTextFields so you should
    either supply valid text for those fileds or re-implement this part of your software.

    kind regards,

    Jos
    Last edited by JosAH; Jul 29 '07, 07:02 AM. Reason: typos: I didn't have my espresso yet

    Comment

    • blazedaces
      Contributor
      • May 2007
      • 284

      #3
      Originally posted by no1zson
      java.lang.Numbe rFormatExceptio n.forInputStrin g(NumberFormatE xception.java:4 8)
      at java.lang.Integ er.parseInt(Int eger.java:468)
      at java.lang.Integ er.parseInt(Int eger.java:497)
      at Inventory2.btnA ddActionPerform ed(Inventory2.j ava:255)
      Ok, so let's look at the printed error, the problem. If we know what the problem is and where it is we will better know how to solve it.

      Now, why does java throw a NumberFormatExc eption? Let's look at the documentation (if I were you, I would make this a habit):
      Originally posted by http://java.sun.com/j2se/1.4.2/docs/api/java/lang/NumberFormatExc eption.html
      Thrown to indicate that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format.
      Now we know what the problem is, next we'll try and understand where it is. The first place the error is caught inside of your class (as opposed to class Integer) is here: at Inventory2.btnA ddActionPerform ed(Inventory2.j ava:255). So here is that class:

      Originally posted by no1zson
      [code=java]
      private void btnAddActionPer formed(ActionEv ent evt)
      {
      // Create cd to add
      CdwArtist newCD = new CdwArtist();
      newCD.setArtist (artistField.ge tText());
      newCD.setName(c dNameField.getT ext());
      newCD.setItemno (Integer.parseI nt(itemField.ge tText()));
      newCD.setNstock (Integer.parseI nt(nstockField. getText())); //This is where it says the error shows up.
      newCD.setPrice( Float.parseFloa t(priceField.ge tText()));

      // Add cd to list
      listModel.addEl ement(newCD);
      currCD = listModel.size( )-1; // sets currCD to added index


      // Clear the text fields after add
      artistField.set Text(null);
      cdNameField.set Text(null);
      itemField.setTe xt(null);
      nstockField.set Text(null);
      priceField.setT ext(null);

      }// end ADD
      [/CODE]
      Quickly, let's take a look at the documentation to know why does Integer.parseIn t(String s) throw that error and it says is throws it because:
      "NumberFormatEx ception - if the string does not contain a parsable integer."

      I don't know exactly the problem yet, but I'm pretty sure by doing the following you can get to the bottom of it: add System.out.prin t for the strings in the method that undergo parseInt. Change your method to look like this and tell us what you see as the output:

      [code=java]
      private void btnAddActionPer formed(ActionEv ent evt)
      {
      // Create cd to add
      CdwArtist newCD = new CdwArtist();
      newCD.setArtist (artistField.ge tText());
      newCD.setName(c dNameField.getT ext());
      newCD.setItemno (Integer.parseI nt(itemField.ge tText()));
      System.out.prin tln("itemField. getText(): " + itemField.getTe xt());
      newCD.setNstock (Integer.parseI nt(nstockField. getText())); //This is where it says the error shows up.
      System.out.prin tln("nstockFiel d.getText(): " + nstockField.get Text());
      newCD.setPrice( Float.parseFloa t(priceField.ge tText()));

      // Add cd to list
      listModel.addEl ement(newCD);
      currCD = listModel.size( )-1; // sets currCD to added index


      // Clear the text fields after add
      artistField.set Text(null);
      cdNameField.set Text(null);
      itemField.setTe xt(null);
      nstockField.set Text(null);
      priceField.setT ext(null);

      }// end ADD
      [/CODE]

      Hope that works and good luck,

      -blazed

      Comment

      • no1zson
        New Member
        • Jul 2007
        • 38

        #4
        I do not know how to reply to this. You both seem to indicate that the problem lies in my ADD button action event, but that works fine.

        It is not until I coded my PREV button action event that the problem occurs.

        Both my nstock and itemno fields are in fact intergers, and my application works without flaw until I coded this PREV button. Does that not indicate a probelm with the PREV button code?
        Code:
        	private void btnPrevActionPerformed(ActionEvent evt)
        		{
        			// Grab Previous cd 
        			CdwArtist newCD = (CdwArtist) listModel.get( currCD-- );
        			newCD.setArtist(artistField.getText());
        			newCD.setName(cdNameField.getText());	
        			newCD.setItemno(Integer.parseInt(itemField.getText()));
        			newCD.setNstock(Integer.parseInt(nstockField.getText()));
        			newCD.setPrice(Float.parseFloat(priceField.getText()));		
        			
        			}// end PREV
        All this button should do is take the information from the previous cd and put it back into my text fields for viewing.

        It works fine when I enter the information into the fields, hit ADD and enter it into my JList.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by no1zson
          I do not know how to reply to this. You both seem to indicate that the problem lies in my ADD button action event, but that works fine.

          It is not until I coded my PREV button action event that the problem occurs.

          Both my nstock and itemno fields are in fact intergers, and my application works without flaw until I coded this PREV button. Does that not indicate a probelm with the PREV button code?
          Code:
          	private void btnPrevActionPerformed(ActionEvent evt)
          		{
          			// Grab Previous cd 
          			CdwArtist newCD = (CdwArtist) listModel.get( currCD-- );
          			newCD.setArtist(artistField.getText());
          			newCD.setName(cdNameField.getText());	
          			newCD.setItemno(Integer.parseInt(itemField.getText()));
          			newCD.setNstock(Integer.parseInt(nstockField.getText()));
          			newCD.setPrice(Float.parseFloat(priceField.getText()));		
          			
          			}// end PREV
          All this button should do is take the information from the previous cd and put it back into my text fields for viewing.

          It works fine when I enter the information into the fields, hit ADD and enter it into my JList.
          You also use that same 'add' method in line 154 or so; as a matter of fact you
          use that method for every action when whatever button is pressed. I'm afraid it's
          a copy/paste thingy ;-)

          kind regards,

          Jos

          Comment

          • no1zson
            New Member
            • Jul 2007
            • 38

            #6
            You are right, I am a beginner but that is just dumb on my part.
            Copy/paste is exactly what I did and did not catch the error until you pointed it out. I wanted to work through one button at a time, so did not change the names when I did it because the new ones were not coded yet and it would error out.

            I have however now changed the PREV button, and although the errors have moved down the chain a bit (I am at least in the right button now) they still point to errors with the same lines of code.
            Code:
            // PREVIOUS
            		btnPrev.setText("Previous");
            		btnPrev.addActionListener(new ActionListener()
            		{
            			public void actionPerformed(ActionEvent evt)
            			{
            				btnPrevActionPerformed(evt);
            			}
            		});
            		getContentPane().add(btnPrev);
            Would the method types be different pulling information from the JList than they were going in? If it were an INT going in, it would be an INT coming back out would it not? The field is coded as such, so I would think nothing would change there. I thought I just had a syntax issue, but it is looking like a bigger problem ... no?

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by no1zson
              You are right, I am a beginner but that is just dumb on my part.
              Copy/paste is exactly what I did and did not catch the error until you pointed it out. I wanted to work through one button at a time, so did not change the names when I did it because the new ones were not coded yet and it would error out.

              I have however now changed the PREV button, and although the errors have moved down the chain a bit (I am at least in the right button now) they still point to errors with the same lines of code.
              Code:
              // PREVIOUS
              		btnPrev.setText("Previous");
              		btnPrev.addActionListener(new ActionListener()
              		{
              			public void actionPerformed(ActionEvent evt)
              			{
              				btnPrevActionPerformed(evt);
              			}
              		});
              		getContentPane().add(btnPrev);
              Would the method types be different pulling information from the JList than they were going in? If it were an INT going in, it would be an INT coming back out would it not? The field is coded as such, so I would think nothing would change there. I thought I just had a syntax issue, but it is looking like a bigger problem ... no?
              Well, as far as I can see your btnPrevActionPe rformed method suffers from that
              same copy/paste virus too: i.e. it too tries to parse an Integer from a JTextField.

              I think you should design your prev/next/add/whatever actions first before you
              attempt to implement anything at all.

              kind regards,

              Jos

              Comment

              • no1zson
                New Member
                • Jul 2007
                • 38

                #8
                That is the crux of my problem, this is my design, this is what I sat down and came up with.
                I have never done this before, so each step I take is the first in that direction, I do not know any other way to do this.
                I understand what you are saying, (I think)
                Code:
                newCD.setItemno(Integer.parseInt(itemField.getText()));
                			newCD.setNstock(Integer.parseInt(nstockField.getText()));
                			newCD.setPrice(Float.parseFloat(priceField.getText()));
                are all parsing integers, but getting text ....if this is the problem, (which I do not doubt what you say), but why would this work in my ADD button but not here?

                Comment

                • JosAH
                  Recognized Expert MVP
                  • Mar 2007
                  • 11453

                  #9
                  Originally posted by no1zson
                  That is the crux of my problem, this is my design, this is what I sat down and came up with.
                  I have never done this before, so each step I take is the first in that direction, I do not know any other way to do this.
                  I understand what you are saying, (I think)
                  Code:
                  newCD.setItemno(Integer.parseInt(itemField.getText()));
                  			newCD.setNstock(Integer.parseInt(nstockField.getText()));
                  			newCD.setPrice(Float.parseFloat(priceField.getText()));
                  are all parsing integers, but getting text ....if this is the problem, (which I do not doubt what you say), but why would this work in my ADD button but not here?
                  Shouldn't that 'prev' button read 'delete'? From what I see from your code you
                  want to delete that CD from your inventory. Deleting a CD is easy: just remove
                  it from your JList model and revalidate the display of it.

                  kind regards,

                  Jos

                  Comment

                  • no1zson
                    New Member
                    • Jul 2007
                    • 38

                    #10
                    No. The PREV button should pull in the previous record.
                    If you see a flaw in my code that does not indicate this please point it out because I do not.

                    The DELETE button will delete a record, but I have not even started on that buttun yet.
                    I put the architecture in the code so that I could see it as a reminder of everything I want to accomplish this week. It is one of several buttons I want to code before Friday.
                    Add was first, it works.
                    Prev is next, it does not work.
                    Next, Delete, Search, Modify, First and Last are all to come ....

                    Comment

                    • JosAH
                      Recognized Expert MVP
                      • Mar 2007
                      • 11453

                      #11
                      Originally posted by no1zson
                      No. The PREV button should pull in the previous record.
                      If you see a flaw in my code that does not indicate this please point it out because I do not.

                      The DELETE button will delete a record, but I have not even started on that buttun yet.
                      I put the architecture in the code so that I could see it as a reminder of everything I want to accomplish this week. It is one of several buttons I want to code before Friday.
                      Add was first, it works.
                      Prev is next, it does not work.
                      Next, Delete, Search, Modify, First and Last are all to come ....
                      Ok, but what do you mean by 'pull in' a record? Copy the values back to the
                      textfields again? If so, just read the CD values and 'setText()' them back to
                      those JTextFiels; there's no need to parse String values, you have to convert
                      ints etc. *back* to String values to be able to setText() them again. There's
                      also no need to create a new CD object for that.

                      Or am I way off again?

                      kind regards,

                      Jos

                      Comment

                      • no1zson
                        New Member
                        • Jul 2007
                        • 38

                        #12
                        Got it. My terminology was throwing you off.
                        I was formatting text as I took it from the GUI fields and put it in the jlist.
                        When I took it back from the jlist to re-populate the fields I had to format it back to its original state.
                        This is what they should have looked like.
                        Code:
                        artistField.setText(newCD.getArtist());
                        			cdNameField.setText(newCD.getName());	
                        			itemField.setText(String.valueOf(newCD.getItemno()));
                        			nstockField.setText(String.valueOf(newCD.getNstock()));
                        			priceField.setText(formatter.format(newCD.getPrice()));
                        I do have a question you could possibly help me with, if I can explain it correctly.

                        Code:
                        if (--currCD<0) currCD = listModel.size()-1;
                        			CdwArtist newCD = (CdwArtist) listModel.get( currCD );
                        When hitting my PREVIOUS button, this function will de-increment my currCD until I am at the very first record, and then loop back to the very last record and continue the process.
                        My list is ever growing, when using my NEXT button, how will be able to tell that I am at the LAST record so that I can loop back to the first and continue?

                        Does that make sense?

                        Comment

                        • JosAH
                          Recognized Expert MVP
                          • Mar 2007
                          • 11453

                          #13
                          Originally posted by no1zson
                          Does that make sense?
                          I guess; Does something like this do?

                          [code=java]
                          if (++currCD >= listModel.size( )) currCD= 0;
                          [/code]

                          kind regards,

                          Jos

                          Comment

                          • no1zson
                            New Member
                            • Jul 2007
                            • 38

                            #14
                            Works like a charm, and alot easier than what I was trying to do.

                            Thanks, you were a great help to me today.

                            Comment

                            Working...