This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JList model elements pre exist, updating of vector does not change model Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JList model elements pre exist, updating of vector does not change model" Watch "JList model elements pre exist, updating of vector does not change model" New topic
Author

JList model elements pre exist, updating of vector does not change model

calvin patel
Greenhorn

Joined: Apr 08, 2012
Posts: 4
so a few entries already exist in the jList. however, once the vector "caller" gets updated the values are not updated in the jList. Please help! thanks!

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> ...the values are not updated in the jList.

they probably are, it's just that you're not showing the list/scrollPane/panel

left = new JPanel();

look at your code, what do you do with 'left'?

(in the absence of the rest of the code) it seem pointless to be recreating all the
components/models etc. If you just work with the model, all should be OK
calvin patel
Greenhorn

Joined: Apr 08, 2012
Posts: 4
So split1 is a part of a larger group of split panels and scroll panels, part of this code shows how the split1 method contains the jList, all in all the code will run, the button split method is what brings up the addCust panel. how im having a hard time bring up. when the enter button is pressed in the addCust panel. the inputs are sent into a vector. The vector then is brought back up in the main file which checkin is part of, in checkin method i have also did a system.out.print to make sure the items that were sent into the vector were able to be pulled. And it does. so i thought i could simply just add an element to the model. however it doesn't show up in my Jlist, the split1() is in charge of the jsplit. any help is greatful!!! i've erased some things from split! since the previous post since it came out useless. all i need to get is the items in the vector to reupdate in the jlist. the addCust() could be ignored because all its items are in the vector wich is already in split1



Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
left = new JPanel();

where is 'left' declared and added to something?

you will probably need to create another .java file, strip everything that has absolutely nothing to do with the JList,
make sure it compiles/runs and demonstrates the problem. then post that code so we can see it on the screen.
calvin patel
Greenhorn

Joined: Apr 08, 2012
Posts: 4
the left = new Panel(), 'left' is added to the checkin() under splitPane where
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setLeftComponent(left);
splitPane.setRightComponent(right);


and the left is created to display the scrollPane. The area of the the code where it has "one", "two,"three","hello" in the array and then added as model.addElement() works and it can be seen.
so everything works fine thus far. this image will show how its being setup. now when then user presses that add customer button. a new panel pops up and a user then can add new information. that information is sent to a vector, which you can see in split1(). a simple system.out.print was tested to see if the items in the vectors still existed, true. the page however does not repaint or refresh after its been added to the model .



[Thumbnail for Screen Shot 2012-04-09 at 11.22.25 AM.png]

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

calvin patel wrote:the left = new Panel(), 'left' is added to the checkin() under splitPane where
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setLeftComponent(left);
splitPane.setRightComponent(right);


and the left is created to display the scrollPane.


That was earlier. The panel which you put into the split-pane is still there; assigning a new JPanel to a variable which used to refer to that original panel does nothing to the GUI.
calvin patel
Greenhorn

Joined: Apr 08, 2012
Posts: 4
So what do you recommend that i do to add in the new elements in the model.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

I have no idea. I can't see where you declared the "left" variable. You used it in a couple of different places but I can't tell which of those happened first or which of them
happened more than once.

However here's what you should do, in general:

(1) Set up the GUI before you do anything else. Including the JList and its model.

(2) When you want to change the model, just change the model. Don't create any new components at that time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JList model elements pre exist, updating of vector does not change model