Code assist for javax package in Eclipse - java

I'm using Eclipse and I've noticed that I don't get a full list of available methods in my Code Assist whenever I'm using anything under the javax package. For example:
JFrame frame = new JFrame();
frame. // this will open up code assist window, but the window only has methods
// inherited from type Object, not the methods from JFrame
I'm using jdk1.6.0_25 as my JRE, and I ensured my source attachment and javadoc locations are correct for rt.jar, and also tried checking everything in Window → Preferences → Java → Editor → Content Assist → Advanced.
I'm pretty new to Eclipse so I'm not sure what I may be doing incorrectly, if there is any other pertinent information that I have left out, let me know and I'll include it.

I have encountered the same problem, and then I worked it out myself.
In my company classes under these two packages are rarely used (in fact, they are not encouraged). So the pre-installed eclipse just adds them to the filter list.
To fix this, open "Window -> Preferences" and search for "type filters" (in my computer it is in Java-Appearance-Type Filters), and you would see a list of filtered packages, uncheck the "java.awt." and "javax.swing.".
Hope this helps!

I have tried this and works perfectly fine in Eclipse Indigo.
javax.swing.JFrame frame = new javax.swing.JFrame(); frame.//here i get all available methods and everything else i am supposed to...
So, make sure you have the packages imported...
Hope this helps!

Related

How to view existing classes in eclipse?

for example if I want to view the class Integer in eclipse, how do I get to it?
I know that there is a method to do it from the code itself for example if I write Integer d = 3; there is a bind i can use and view the class Integer, I just can't find it. Anyone knows what I am talking about ?
Simply place the cursor within "Integer" and press F3. Alternatively, you can Navigate->Open Type in the menu bar (or usually press Ctrl/Cmd+Shift+T) and that will display a "type search" window. There you just start typing the name of the class you want to jump to. You can even enter strings such as NPE there ... which would be looking for any class with those uppercase letters (often referred to as "camel case"), like NullPointerException for example.
That will "jump into" any known class in what's considered the current Java Build Path.
If source code is available, you can thus look into Integer.java.
If source code is missing, you will look at something like, but not exactly, de-assembled byte code.
The latter can happen if your project / workspace setup is missing the source files for libraries. In such cases, you have to go into your project setup and manually add source code. (most libraries come with extra zip files containing the Java sources; and those zip files can be added to the library definition in Eclipse). Since Eclipse it will show you whatever copy is on the current selection's Java Build Path, if you're developing with Java, having that be a JDK will allow its sources to appear automatically. It's best to have the Installed JREs preference page only point to JDKs if you can.

In eclipse, how can I find where in my classpath a type is coming from?

Maybe I'm misunderstanding something, but..
I want to be able to see that eclipse is getting Foo.class from a .jar (somewhere in the classpath) when it builds project B.
If I use the 'open type' (Ctrl + Shift + T) it seems that that just shows me all the places that Foo.class exists in my WORKSPACE?
Many thanks..
EDIT: I'm trying to find which jar is introducing a class into my code. It's not my jar. I don't have the source. I can't therefore open it and click it. I want a window that I can type in a type name, like 'Foo.class', and it tells me where that class is being brought in in my classpath. That must be quite simple? Ideally it would also tell me which occurrences later in the classpath were being hidden because it found the first one first. Does that make sense or am I talking nonsense?
EDIT: Guess I'm not making it clear. I don't have a piece of code that uses Foo. It's that somewhere in some included open source library something calls something calls Foo. So I can't highlight or right click anything. I guess I could write a piece of code that has it in? Seems a bit clunky..
Came here looking for the same, so though the question is two years old:
In eclipse Mars, if you press shift+control+T / ⇧+⌘+T on mac to bring up the "Open Type" dialog, the package as well as the name and path of the jar file is shown in the bottom of the window for a selected class.
Alternate Solution : particularly if you want to know the jar files which have needed class , you can search using WINRAR.
Use Find in WinRAR
i) Open WinRAR
ii) Open lib folder ( which contains all jar files ) in WinRAR
iii) Click on Find , type any classname (ex : ClassWriter.class )
iv) Click on OK
you will see all the classes which are named as ClassWriter.class in all jar files in lib folder.
Since there seems to be no good solution or plugin for this, I often create a dummy class in the root of my project:
public class Find {
public static void main(String[] args) {
System.out.println(
SomeClass.class.getProtectionDomain().getCodeSource().getLocation());
}
}
Then I just delete the class. A plugin would be nice :)
Look for .classpath file in your project.
OR
Where ever class Foo is used, go to that statement, while Ctrl key is pressed, left click the class name. Eclipse will take you to the location of Foo class. This will the Foo class eclipse is referring while building your code.
Right click on the class name, then select "Open declaration" (or just press F3), if you don't have a source attached, you can do it at that point. In the package explorer you have the functionality "Link with Editor" (a button with a couple of arrows going back and forward), that redirects you to the jar of the class. If you don't have the source, you still can use the "Link with Editor" functionality to see the propietary jar

Empty Netbeans 7 palette? How to restore it?

I use Netbeans 7 on Kubuntu 12.04. I start Netbeans like this:
netbeans --cp:a /usr/share/java/xercesImpl.jar &
cause of known issue with Netbeans and Kubuntu 12.04. In the middle of my project my palette with Swing components just .. disappeared!
I see only sth like this:
How to restore default Netbeans palette?
I checked Ctrl+Shift+8 shortcut but with no results - the problem is still the same.
**EDIT:
I dont know what I did but now I see ONLY EMPTY palette :( : **
I also tried this:
1) I cd'ed to /home/mazix/.netbeans/7.0/config/Windows2Local/Groups/commonpalette
, ls'ed and saw only this: CommonPalette.wstcgrp
2) cd'ed to /home/mazix/.netbeans/7.0/config/Windows2Local/Components and saw this:
AnalyzerTopComponent.settings output.settings
AnalyzeStackTopComponent.settings projectTabLogical_tc.settings
breakpointsView.settings projectTab_tc.settings
CallHierarchyTopComponent.settings properties_1.settings
callstackView.settings properties.settings
CommonPalette.settings refactoring-preview.settings
ComponentInspector.settings
ReporterResultTopComponent.settings CssPreviewTC.settings
resultsView.settings debugging.settings
search-results.settings DeclarationTopComponent.settings
services.settings evaluator.settings
sessionsView.settings favorites.settings
sources.settings find-usages.settings
StyleBuilderTC.settings gsf-testrunner-results.settings
svnversioning.settings hgversioning.settings
synchronize.settings JavadocTopComponent.settings
TaskListTopComponent.settings localsView.settings
TerminalContainerTopComponent.settings
MultiView-java#007Cform#007C_1.settings threadsView.settings
MultiView-java#007Cform#007C_2.settings versioning_output.settings
MultiView-java#007Cform#007C_4.settings watchesView.settings
MultiView-java#007Cform#007C.settings Welcome.settings
navigatorTC.settings
and didnt see any _hidden files :(
Open NetBeans and choose Window -> Palette
It will appear but it will be empty because you didn't choose a GUI class yet.
To fill the palette with the GUI components like labels, follow these steps:
Create a new project .
Right click in the package name or project name, and choose New -> Other...
In the New File dialog box, choose the "Swing GUI Forms" from category and the "JFrame"
Form file type sub window. Click Next.
Enter name lets say "MyGUI" for the new the class which you created now.
The palette window is now full with components like labels, text,checkboxes, ...
if not appear yet make sure to press "Design" button in the upper of the GUI class bar "MyGUI"class
I got the same issue and this work for me window -> reset window. hope it work for you :)
I think the same problem occur here.Check this solution.it may helpful to you.
This steps for restore the default palette?
Exit the IDE.
Go to your user directory and go down to config/Palette subdir. In this directory, the files or directories deleted from the default palette content are presented as empty files with _hidden suffix in their names.
Delete these _hidden files to let the palette categories and items appear again in the IDE.
I think this will help you
Do one thing, simply right click on your netbeans project and then open it. It resolves the problem. You will observe if u open a new project the palette is there, so just copy the project with a different name, its will solve your problem.
In my case after creating a new project without a default constructor, the search box at the palette holds a single character i.e. '='. this results in an empty palette too.
In that case the solution is obvious: just delete the content of the search input.
It puzzled me for a moment, though, not noticing the search input field content.
I had the same situation with my netbeans. The only solution I did was to backup my project folder (saving it to other drive). Then re-install the netbeans. Afterwards I re-paste the project folder at the directory and re-open it.
Right-click mouse button at palette box. Choose command "reset palette".
I encountered the same problem. Just check the bottom of the palette to see if there is a search box open. If there is, close it. Then the palette will be available once again.
So, nothing suggested here worked for me, I am leaving my solution.
You create the project, name it.
Create a package.
Click on the package with the right mouse button
select New filme
select Other
select AWT GUI Forms
select Frame form
Now you should see the menu at the right part of your screen with the option to create buttons, labels, etc.
As of 2021 for mac users;
Open your NetBeans app and click on "windows" located at the top menu of the application. A drop down will appear.
Scroll down and click "IDE Tools". You'll see another dropdown containing list of items including palette.
Click on the "palette". This will make the palette visible.
That's all!

Eclipse autocompletion problem

Just installed Eclipse Helios (Win7 64) and I'm having a strange problem. I type syso-Ctrl-Space which is expected to complete to System.out.println("") but it doesn't work! I searched the web for about an hour now, I set Preferences > Java > Editor > Content Assist to defaults, nothing. Everything else seems to work. Ideas?
To be clear: the shortcut works, it completes everything except "syso" as seen so far, on syso (also tried sysout) it says "No Default Proposals". I couldn't find this kind of shortcuts in the Content Assist, but I set them to default anyway.
If you still cant get auto-completion working,try enabling the Template proposals under Content assist menu.This is the exact location,
Windows->Preferences->Java->Editor->Content Assist->Advanced
And make sure you have only one entry for syso(Under Templates menu).
I believe the right template is "sysout" and I believe this can be configured somewhere but could not tell you where. Try sysout and then Ctrl+Space
It's a template, you can find all templates under
Window -> Preferences -> Java -> Editor -> Templates
There you can see that the template name is "sysout" this will then trigger the string substitution for System.out.writeln() but you can change both the template name (if you prefer syso) and/or the actual code produced by invoking the template
Cheers
I am using Eclipse Galileo and had the same problem. Even after trying the above proposed solutions but it didn't work. After making the below change it finally comes out.
Go to Windows->Preferences->Java->Editor->Templates
Select sysout template and edit it.
Change the context from Java statement to Java.
And it worked for me. I hope this will be helpful for you.
As Peter stated, it is under Window -> Java -> editor -> templates.
Look for the line with the following values.
sysout "Java Statements" "Print to standard out" "on"
the preview should be as follows...
System.out.println(${word_selection}${});${cursor}
Your cursor needs to be located in a place where it would be legal to get that line. If your cursor is within a method definition and you type syso you will get the replacement. However if your cursor is in the portion of the text outside of any method definition, say where you declare variables for your class for instance, then syso will not suggest the illegal line system.output.println();.
I had this problem, read all the answers here, became convinced that it MUST be working in my copy, and realized I had been typing syso BELOW the closing } of my last method instead of in the method.
Eclipse on!
You may try to set the shortcut of Content Assist with ALT+L, if it works, then you can choose your favorite shortcut again. (The shortcut Ctrl+Space conflicts with the shortcut of switching input method). In eclipse on linux, the shortcut of Word Completion is ALT+/, so if you set this as the shortcut of Content Assist it also conflicts.)
Just go to the below address:
Windows->Preferences->Java->Editor->Content Assist->Advanced
and click restore default..........that's all
its work like a charm again.
Also check in this eclipse menu:
Windows -> Preferences -> Java -> Appearance -> Type Filters
If you see java.* or javax.* here then try removing it (or Restore Default will do the job) and see that works, it did for me.
Just found the solution for Eclipse Luna: write syso and press CTRL+Space and click on "enable intelligent code completion" and you are set.
I am sure you can find it somewhere in the options as well but this way it is fast and easy!
DIRTY WORKAROUND:
You can try out the following AutoHotkey-Code if you're still struggling like I am (STILL haven't been able to fix it myself)
#persistent
#ifwinactive ahk_class SWT_Window0 ; eclipse java
:*:syso::
sendraw System.out.println()`;
loop, 2
send {left}
return
#ifwinactive
You need to write this in a .ahk file and run it (AutoHotkey needs to be installed). You might wanna put this file into your startup folder. It's a very useful tool, you might wanna expand it one day.
You might have overlapping shortcuts.. Goto 'Overview' than the 'Keys' subsection. Type "ctrl +space" in the 'filter text' section. You should see the "content assist" and probably another command with the same shortcut. If another shortcut does exists, change its shortcut to something else.

Generating code stub from class and javadoc

Is anyone familiar with a tool that generates code stubs with meaningful names from class and javadoc?
The real question should've been "I have classes without debug information and a matching javadoc, but my IntelliJ IDEA 8.0.1 (please, no IDE wars) doesn't take into account the javadoc and shows me "void setLocation(Object object, String str1, int i1, int i2);" instead of "void setLocation(Object component, String name, int x, int y);" - which makes a HUGE difference, both to auto-completion and ease of use". If this can be answered, I'd be satisfied as well.
I suggest to file a bug against IDEA along these lines: If a class has no debug information but has JavaDocs, IDEA should use the JavaDoc to determine the names of the parameters.
Btw. Eclipse has the same problem. :)
Go to Project Structure (in 8.x that's Ctrl+Alt+Shift+S) -> Modules -> (select the module you're coding) -> Dependencies. Select the dependency (either JAR file or directory) that contains the third party component. Click on the "Edit..." button, a new window will pop up. If you have a JAR file or a folder on your computer with the javadocs, select "Attach JavaDoc..." and point IDEA to the location. You can also point it to an online API using "Specify JavaDoc URL..." - just give it the root of the javadoc-generated output. Select OK and close all the other dialog windows.
Go back to the editor, and highlight a method in the third party component. If you press Ctrl+Q, you should see a javadoc popup with full parameter descriptions.

Categories

Resources