• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

check if setEditable is defined as a method

 
albert kao
Ranch Hand
Posts: 252
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to check if the setEditable method is defined as a method for a class such as JComponent?
e.g.
 
Paul Clapham
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it isn't defined as a method, the compiler will tell you so.

Edit: Wait a minute... perhaps you actually meant you want to check if the JComponent object is actually an object of a subclass which does have a setEditable() method? In that case you should probably choose the actual subclass you're interested in (say JTable for example) and then use the "instanceof" operator:


Or perhaps you should reconsider that design entirely. When beginners write code like that, it's often because they haven't figured out to keep references to components that they want to work with. If you don't keep track of those references, you are reduced to grubbing through a pile of components to try to get the references back. It's possible your question arises from that sort of programming.
 
Ivan Franko
Ranch Hand
Posts: 46
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what about idea use reflection? something like this:



but.. really Paul Clapham - great answer!
 
Paul Clapham
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reflection is certainly an answer to that question, too. But usually you would use reflection if you were writing a general-purpose framework, like for example an IDE or a GUI designer. If you find yourself using reflection for an application with a specific purpose (like a calculator, for example) then there's a good chance you shouldn't be going there.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You ought to be looking in the API, and you find this, or this, so you can work out from those methods whether your class does or does not have a setEditable method.
You can also look in the API index under S, but there will be many thousands of lines for you to look at. Here, ctrl-F is your friend
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic