File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Modifying a GridLayout/Changing Labels Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Modifying a GridLayout/Changing Labels" Watch "Modifying a GridLayout/Changing Labels" New topic

Modifying a GridLayout/Changing Labels

Matthew Fyffe

Joined: Jul 11, 2003
Posts: 16
I'm making a program that uses a 10 X 10 GridLayout in which each position on the grid is a certain JLabel with an image icon in it. I have made a command so that when you type a letter, it loads up a different image, and then, upon clicking on a certain position on your Grid, it will remove that JLabel and place the one you have there. I tried doing this simply by replacing the JLabel at that position but it didn't modify anything. So then, I removed the JLabel at that position from my JPanel itself and then want to add the new JLabel in it's place at that position. However, the GridLayout takes my newly added JLabel and plops it down at the bottom.
Is there anyway I can add a JLabel to my GridLayout at my desired position? Or, if that's not possible, how do i change a JLabel from one image to another without removing it and adding it to the program again?
Thanks, I'll offer more info as is needed.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
here's a simple demo

I agree. Here's the link:
subject: Modifying a GridLayout/Changing Labels
jQuery in Action, 3rd edition