File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Displaying panels... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Displaying panels..." Watch "Displaying panels..." New topic
Author

Displaying panels...

celine mcgowan
Ranch Hand

Joined: Nov 22, 2003
Posts: 36
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


We've heard that a million monkeys at a million keyboards would eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true.<br />- Robert Wilensky
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Read up about layout managers in your Swing reference. You need to use one.

Jules
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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

Joined: Nov 22, 2003
Posts: 36
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
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Swing / JFC / AWT forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
clio katz
Ranch Hand

Joined: Apr 30, 2004
Posts: 101
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

Joined: Apr 30, 2004
Posts: 101
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

Joined: Nov 22, 2003
Posts: 36
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

Joined: Apr 30, 2004
Posts: 101
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

Joined: Nov 22, 2003
Posts: 36
No need to be modest Clio! I get the feeling you've helped many people before me!!!

Thanks again for your time...
Celine
 
 
subject: Displaying panels...