jhlu87
jhlu87

Reputation: 4019

How do I open an included java class(for example JButton) in IntelliJ IDEA 10?

I want to be able to open up the JButton class and see the code inside it. The reason is because I want to override one of the methods, but I want to make sure I include all the functionality that that method normally has. Also, it'd be a good way to learn. I know I can do it when I've had errors by clicking on the class in the error messages. But any ideas on how to bring it up normally?

Upvotes: 2

Views: 340

Answers (4)

CrazyCoder
CrazyCoder

Reputation: 401945

Go To | Class (Ctrl+N), type JButton (Include non-project classes checkbox will be enabled automatically if no such classes are found in your project).

If you already have JButton usage in your code, you can navigate to its source using Ctrl+B while the caret is on it.

Of course you need sources attached to the JSDK, but it should be fine by default (as JSDK installation has sources on most platforms). If you are on Mac, you will have to download them separately and attach to the JSDK configuration in File | Project Structure | SDKs.

Upvotes: 1

Paul
Paul

Reputation: 20061

You need to download the Java source code. If you're using Java 1.6, for example, you can go here to get it. Unzip it somewhere on your local disk.

When I need to look at the source code of a Java class I then navigate to the source class and drag it into my IDE.

If you want to ensure you get all the functionality of the original method, call the original method as part of your method. Using super gives you a reference to the overridden method, e.g. super.overridden();. Don't just copy the Java source into your method.

Upvotes: 0

Sergii Zagriichuk
Sergii Zagriichuk

Reputation: 5399

If you have sources just press Ctrl+B on JButton, if you have no, download sources, add to configuration of project and press the same combination

Upvotes: 1

Sean
Sean

Reputation: 7737

Download the Java Source code here: http://www.oracle.com/technetwork/java/javase/downloads/index.html

Also don't forget about the super keyword which you can use to interact with the extended class

Upvotes: 0

Related Questions