• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Modifying a GridLayout/Changing Labels

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here's a simple demo

 
If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!