8 Replies - 601 Views - Last Post: 17 June 2011 - 07:37 AM Rate Topic: -----

#1 AggressiveFish  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 21-April 11

Unknown Object

Posted 16 June 2011 - 08:08 AM

I have an applet with a ton of JPanels, nested JPanels, etc.., on the page. There are also alot of JLabels and such and on the page there is a small white square showing I can't determine what it is by looking at the code. Is there a way to have an onclick event tell me what object it is or some similar quick way to determine that the object is? Thanks.
Is This A Good Question/Topic? 0
  • +

Replies To: Unknown Object

#2 maniacalsounds  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 117
  • View blog
  • Posts: 472
  • Joined: 27-June 10

Re: Unknown Object

Posted 16 June 2011 - 09:22 AM

Quick Reading:
http://www.programme...ame-in-runtime/
Was This Post Helpful? 0
  • +
  • -

#3 AggressiveFish  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 21-April 11

Re: Unknown Object

Posted 16 June 2011 - 10:31 AM

Not exactly what I was looking for. I want to have it so I can click anywhere on the applet and have the object type returned (whether it is a JLabel, JPanel, etc..,).
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,273
  • Joined: 27-December 08

Re: Unknown Object

Posted 16 June 2011 - 10:34 AM

Add MouseListeners to all your JComponents and display the Class. Each Object has a class field you can access.
Was This Post Helpful? 0
  • +
  • -

#5 AggressiveFish  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 21-April 11

Re: Unknown Object

Posted 16 June 2011 - 10:53 AM

So there's no way to add it to JApplet and have it capture all children mouse events? I was hoping there'd be some shortcut due to the number of objects on the page. I did find what object it was. I'm putting JPanels into cells of a GridBagLayout (larger JPanel) but to separate them apart I'm putting empty JLabels into cells in the middle (to take up space). So on 1 row there's a JPanel, then JLabel, then JPanel, then JLabel, and the JPanel. The problem is sometimes the JLabel ends up overlapping a JPanel (some cases). So the JPanel with it's drawing on it has a white block in the middle of it (which I found out is a JLabel). How can a JLabel overlap the JPanel when they are in different cells (i.e. different gridx setting)?
Was This Post Helpful? 0
  • +
  • -

#6 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,273
  • Joined: 27-December 08

Re: Unknown Object

Posted 16 June 2011 - 11:04 AM

You could try adding it to the JApplet and returning the class of the MouseEvent's getSource() method.
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: Unknown Object

Posted 16 June 2011 - 04:52 PM

That will work when you will click on a graphical object, but the OP problem is to identify the lack of an object somewhere so if you click on it it won't react.

You can write a method that retreives all the JComponent from a container and print the getBounds() of each of them.
Or loop for all your pixels (for int x = 0; x < getSize(); ++x))and call the contains(x, y) of all components, if none of them contains your Point(x,y) it means there is nothing there
Was This Post Helpful? 1
  • +
  • -

#8 AggressiveFish  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 21-April 11

Re: Unknown Object

Posted 17 June 2011 - 07:07 AM

Hi pbl,
Upon writing you a detailed description I noticed something while trying to explain the setup, went back, checked, and found the problem. I had a gridwidth for the JPanel because it spanned 3 cells below it but I forgot to reset it back to 1. So JPanel was spanning 3 cells (starting at 4), then I inserted a cell for JLabel at 7, and then another JPanel at 8. The first JPanel and JLabel had gridwidth set to 3 so the JLabel overlapped the second JPanel. Something to keep note of in case I need to do this sort of thing later - unlike HTML so interesting. Thanks again, next time I'll try explaining to myself first :-)

Rob
Was This Post Helpful? 0
  • +
  • -

#9 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2831
  • View blog
  • Posts: 11,992
  • Joined: 20-September 08

Re: Unknown Object

Posted 17 June 2011 - 07:37 AM

You could decorate a call to Container.add that sets the tooltip text for your components:



   private void addIdentified(Container c, JComponent comp, Object constraints, String text) {
       comp.setToolTipText(text == null || "".equals(text)? comp.getClass().getName() : text);
       c.add(comp, constraints);
   }


Was This Post Helpful? 2
  • +
  • -

Page 1 of 1