• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Displaying panels...

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

Sorry to bother you all again. I am again having probs with an accursed LED panel thingy. I have finally got it to compile etc - thanks everyone for your help with that (see post here:Non-default constructor problem)! Anyway, I have a method which updates the gifs which are in an LEDPanel:


I am calling the above method 8 times in another class in order to output 8 LED displays. Here's that code:


When i run LEDPanel, i only get one panel displaying. It seems to be the last panel, but i'm not sure! Does anyone know why there is only one LED displaying, and not all 8?

Thanks again all.
Celine
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read up about layout managers in your Swing reference. You need to use one.

Jules
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it's the size, possible this line
setBorder( BorderFactory.createEmptyBorder( 20, 20, 20, 20 ) );

should be
ledPanel.setBorder( BorderFactory.createEmptyBorder( 20, 20, 20, 20 ) );
 
celine mcgowan
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Thanks for your help. I have changed the code in LEDPanel so that there is a GridLayout manager (one row, eight columns) on the main Panel:


This still only outputs one LED... Am i doing something really silly?

Thanks,
Celine
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i can't really tell from the code fragments, but it looks
like you're adding each LEDPanel (twice) and doing some
layout stuff in _updateLED:

CODE FRAGMENT...
//add the whole panel to the window
setLayout( new BorderLayout() );
add( ledPanel );
setBorder( BorderFactory.createEmptyBorder( 20, 20, 20, 20 ) );


Is there another 'shadow' window that you also populate
when you invoke main?

if not, it s.b. ok to remove/relocate this code.


My only other comment would be that your _updateLED method
also appears to allocate the *same* JLabel set (i'm guessing
they are JLabels...) to each panel. As I recall, Swing
won't like this. If you continue to have problems, try
replacing the .setIcon calls with new JLabel eg

eg replace

bottomRight.setIcon(new ImageIcon("vertical_lit.gif"));

with something like

bottomRight = new JLabel(new ImageIcon("vertical_lit.gif"));


good luck!
 
clio katz
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok celine,
i looked at your other post with more of your code and i believe i see what you're asking ...

i think my previous response pretty much still applies: you have a couple of places where you are instantiating some objs you don't use, and the updateLED references LED obj that haven't been properly initialized ...

Last comment would be to check your code to see where you are making changes to the LED visual model - probably only want to do things like layout changes once: at init time etc

i couldn't resist re-organizing your code into one LEDPanel class:



hth
 
celine mcgowan
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Clio,

You're a lifesaver! I changed "setIcon" to "new JLabel( new ImageIcon..." & took out the panel formatting stuff from the updateLED method as you suggested and it works!!! Makes sense i guess - how can you reset an icon you haven't initialised in the first place. I won't forget this lesson in a hurry!!! Thank you so much for your help & for giving so much of your valuable time to do so.

I have saved the code you posted which is a much more elegant solution to this problem - thanks again. I'm still very much a newbie though & i don't totally understand what's happening there, but i'm gonna spend a bit of time looking at it & running it etc so that i'll understand it by this evening.

Gratefully yours,
Celine
 
clio katz
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
bravo to you for your hard work and persistence, Celine! i myself learn better by example than by instruction, and so i have benefitted from the wealth of java examples on the web. i'm glad to give back when i can.

thank you for your feedback - 99% of the time i never hear anything so i don't know if i'm helping or harming ... it's nice to hear back, and nicer to have actually helped for a change:-)
 
celine mcgowan
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No need to be modest Clio! I get the feeling you've helped many people before me!!!

Thanks again for your time...
Celine
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic