• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JList in JScrollPane

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a JList inside a JScrollPane.getviewport.setview.... whatever. I have a separate thread that parses an xml file, and adds components to the JLists defaultlistmodel as it goes along with setElement(String). The application seems to have a mind of its own sometimes.
I start the app, it starts to list some of the elements in the jList and then the list just goes blank. it does it a second time when I start the app again. then sometimes on the third time it loads all the elements and I can see them. now when I scroll down past the last element that was viewable from the top I cant select it. I select it, but I dont see the hi-light. once i scroll the selected but not hilighted element out of the viewable area and back in, its suddenly selected.
So, in all I have 2 problems. one, the elements not displaying when I start the app, and two, the elements not being hi-lighted. Does anyone have any idea what could cause this?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post your code... it could be a problem with the threading, the XML, Swing events, or many other things...
 
A. Wolf
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here it goes:

NEXT CLASS------------------------------------------------

NEXT CLASS-----------------------------------------------------------------

and then i used javalayer to play the files. I have also noticed lots of little mistakes in the filenames and locations of the files when i retrieve them.

[Nathan - edited to remove long lines in code.]
[ November 14, 2003: Message edited by: Nathan Pruett ]
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the problem is that you are mixing AWT and Swing components... Frame is an AWT frame, and you are adding a Swing JScrollPane to it. To fix this, use only Swing components, like JFrame, JButton, etc.

Some other things you should do : use a layout manager instead of null... this can lead to sizing problems later. There are also better ways to instantiate all the widgets than the way you are doing it. Take a look at the refactored code for your window below.


[ November 14, 2003: Message edited by: Nathan Pruett ]
 
A. Wolf
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmm... it still does that flicker in the list. once, twice and then either it stays off or it comes back on to stay. I have to say, your code looks very neat compared to mine, and makes more sense logically. As to layout managers, if there was an emoticon for pain i'd put it here -> ain: . for some reason my apps never look "cool" when i use them.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That really doesn't make sense... all your code does is add things to the model. They are never removed, so there should never be a case where the list is not populated.

It sounds like either you still have a problem somewhere mixing AWT and Swing components, or that there is a problem with the other thread updating the model. If it is a problem with threading, try minimizing and restoring your frame when it shows up with nothing in the list. If it looks normal after you've restored the frame, then you've got a threading problem, and to fix it you can do one of two things. You're going to have to either wait until the list is completely populated before you show the frame, or you're going to have to use something like SwingUtilities.invokeLater() or invokeAndWait() to make sure you update the model in the event thread.
 
A. Wolf
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, I've consistently noticed this message popping up every time it does NOT work, and after i try to resize the window like you said.

2003-11-20 14:11:14.119 java[708] Java couldn't paint in Java_apple_awt_CRenderer_doRect, no focused view.


it's done that with other applications too, but I haven't seen any problems with them. this is the first time something is giving me trouble and this is displayed. it consistenly only appears every time my app fails. any suggestions?
[edit] Q/A
found this on apples website...
Q: Terminal/Console reports "Java couldn't paint in Java_apple_awt_CRenderer_doRect, no focused view."

A: This is a known issue with Swing applications under 1.4.1 Update 1, as well as Java 1.4.1 on Panther. It specifically refers to a failed paint call, but typically has no noticeable effect on applications and can be safely ignored.
but it doesn't draw my list items...
[ November 20, 2003: Message edited by: A. Wolf ]
 
And then the flying monkeys attacked. My only defense was this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic