5 Replies - 193 Views - Last Post: 30 January 2013 - 06:18 PM Rate Topic: -----

#1 extremeblueness  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 186
  • Joined: 22-October 12

Removing From JPanel

Posted 29 January 2013 - 05:26 PM

Hi. I was wondering if there's any method to remove everything from a JPanel without knowing specifically what's in that JPanel. If not, is there a way to detect what's inside that JPanel?

Potentially helpful information:

-I'm using a GridLayout for those JPanels.
-I can freely switch to any LayoutManager for those JPanels
Is This A Good Question/Topic? 0
  • +

Replies To: Removing From JPanel

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10185
  • View blog
  • Posts: 37,603
  • Joined: 27-December 08

Re: Removing From JPanel

Posted 29 January 2013 - 05:30 PM

You can use the removeAll() method, but it's generally not a good idea to do this. What are you trying to accomplish specifically?
Was This Post Helpful? 1
  • +
  • -

#3 extremeblueness  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 186
  • Joined: 22-October 12

Re: Removing From JPanel

Posted 29 January 2013 - 05:41 PM

@macosxnerd I'm trying to remove all cards in a 1x1 GridLayout so that the user doesn't see those cards once they've been played.
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10185
  • View blog
  • Posts: 37,603
  • Joined: 27-December 08

Re: Removing From JPanel

Posted 29 January 2013 - 05:49 PM

JLabels and Icons are the way to go. Set the Icons rather than redoing the layout.
Was This Post Helpful? 0
  • +
  • -

#5 extremeblueness  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 186
  • Joined: 22-October 12

Re: Removing From JPanel

Posted 30 January 2013 - 05:33 PM

@macosxnerd101 what would be wrong with the removeAll() method that you mentioned? And my JPanel serves as an image class.
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10185
  • View blog
  • Posts: 37,603
  • Joined: 27-December 08

Re: Removing From JPanel

Posted 30 January 2013 - 06:18 PM

It's more expensive computationally to revalidate() the JPanel than it is to switch out an Icon on a JLabel. In addition, it takes more man-hours to write the code to do so.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1