I am using Eclipse Juno and have never had any problems with it, until its content assist stopped working only in some parts of my code. The code below shows what I am talking about:
mWTBatch.setText("Here content assist works");
medCopyBtn.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
mWTBatch.setText(mRTBatch.getText());
mWTExp.setText(mRTExp.getText());
mWTName.setText(mRTName.getText());
mWTQuantity.setText(mRTQuantity.getText());
/* Here content assist is not working */
}
});
mWTBatch.setText("Here it is working again");
That piece of code is just inside one method of my class. The problem is that it works fine inside the methods of the class, but inside objects (new ActionListener(){}) it returns "No default proposals". It has this behavior when I either use "Ctrl+space" or type in "." after the object I want to get suggestions of. I've already searched here for the solution and googled it, but couldn't find a solution. What I have already tried:
Window->Preferences->Editor->Content Assist->Advanced and checked Java Proposals. It didn't work. I've even tried checking it myself, without just using Restore Defaults. I also tried the Java Proposals from the other table. Nothing. At last I tried checking all the fields with Java on them. Nothing worked.
Deleted my workspace folder completely, created a new one and imported my project. As my project is from an SVN repository, I used the project folder inside "trunk" folder, but I didn't copy the content of the folder to the workspace when importing (I need it to be in the repository). Still nothing, it continues with the error.
I reproduced the same situation of the code above into another class of another different project, which was also imported to the workspace, but having its content copied to it. The content assist worked for that one.
I then re-imported the project with the original code from above, but this time copying its content to workspace (which means it had nothing to do anymore with the SVN repository). It didn't work either.
I also checked if the ctrl+space is bind to the content assist on Eclipse settings and it is ok. I also checked if it had nothing to do with advanced key settings of Windows 7 language bar. I had seen on the internet that could be problem, but it was not my case.
I even created a new Java project on the workspace and copied the .java files one by one from the old project, set all the build path manually and in the end it still doesn't work.
For all the first four cases above I also cleaned the projects and closed and reopened them, not forgetting to refresh it after each action. Could anyone tell me how to fix this? I would like to find a solution to this problem, so that others may not be like me on it for 2 days. I think my question is important because I am gathering here many probable solutions found by googling the problem and from StackOverflow, and nothing solved it.
I stumbled into this issue the other day, and after seeing this post thought that I'd have to just live with it.
However, I did find a "hack" around it:
mWTBatch.setText("Here content assist works");
medCopyBtn.addActionListener( //<---------------------- Problem arises because we're inside a function declaration ...
new ActionListener()
{ // <--------------------------------------------- ... yet we're trying to write a function
public void actionPerformed(ActionEvent e)
{
/* Here content assist is not working */
}
}
);
mWTBatch.setText("Here it is working again");
From the content assistants point of view, this is just plain wrong, so we need to give it a little help:
mWTBatch.setText("Here content assist works");
medCopyBtn.addActionListener(
new ActionListener()
// <--------------------------------------------- CURLY BRACKET MISSING
public void actionPerformed(ActionEvent e)
{
/* Here content assist IS WORKING */
}
}
);
mWTBatch.setText("Here it is still working");
This will obviously give you an error upon compilation time, but it gives you full access to the content assist for the rest of the function declaration.
Also, it doesn't matter which curly bracket you remove from inside the function declaration, so long as it's an opening curly bracket.
One other point, if you only remove the opening curly bracket like I did above, then eclipse will NOT add in another closing curly bracket automatically for most cases (because by the time you enter the new opening curly bracket, you've equalised the opening vr closing of curly brackets). You can get around this by deleting the closing curly bracket as well, but then you have to remember to put two curly brackets back.
Hope that helps the 1165 views this question has garnered over the past year =)
Do a search for "Change display language" on the start menu. 'Change keyboards' > Look to see if you have any non English keyboards under 'General' > 'Installed services'. If you have more than just English then pressing Ctrl+Spacebar is changing your focus from Eclipse to the language selector on the taskbar. Remove any other keyboard languages from the list if that is your problem.
Related
When I write my code in NetBeans, there are times when I want to add/remove if statements and loops. However, every time I want to add/remove a statement but keep the content, I have to fix all the indenting for the contained code. Likewise, every time I try to paste code into a statement, the indenting is all messed up and I have to fix it.
Is there any way to highlight the code and fix indentation?
I'm aware that Eclipse has an option to fix all formatting upon saving. I'm not looking for something that changes formatting upon saving, rather only something I can click on the moment I want the formatting fixed. I put an example of what I'm talking about below.
if (condition == true){
//pasted code
//pasted code
//pasted code
}
or
//other code
//removed if statement
//original code that is spaced too far right
//original code that is spaced too far right
//removed }
//other code
Try to paste using Ctrl + Shift + V.
If it worked, look at the netbeans options to configure the shortcut you want.
To change shortcuts go to : Tools > Options > Keymap
Here is a table of defaults shortcuts in netbeans : https://netbeans.org/project_downloads/usersguide/shortcuts-80.pdf
It might be useful, you can notice the "Ctrl-Shift-V Paste formatted" shortcut.
I've created a custom editor for eclipse but I'm having trouble setting up an auto-complete feature (when a developer enters an opening bracket the editor auto-generates the closing bracket). I've looked at the java example and spent some time googling but I'm having trouble finding any information. Any help is greatly appreciated.
I've come up with a solution, sort of. I created a class that implements IContentAssistProcessor. I overrode the computeCompletionProposal function and in it i used the ITextViewer, that is passed in, to get the document. Then I used the IDocument.replace() function to add a closing bracket anytime an open one is typed. The problem with this is the cursor is moved to the end of the closing bracket. any suggestion on how to move it in between the brackets?
So I am new to the Intellij Idea IDE and so far I like it a lot. Just having some trouble getting the code style settings exactly how I like them for Java. I am a fan of not using braces for one line if statements but I like for them to be on two lines:
if(true)
dosomething();
Right now when I run code formatting in Idea, it moves up into one line:
if(true) dosomething();
and I find that very hard to read, but I cannot seem to get the settings just right. Can anyone help me out and tell me what I need to set to keep it on two lines but still no braces? Feel pretty dumb not being able to find it. Thanks!
Deselect Simple blocks in one line in settings -> CodeStyle -> WrappingandBraces, then it should work. It worked for me.
Have you tried Control Statements on one line? Does it for me.
Well this might sound strange, but even I had the option simple blocks in one line unchecked. And I was facing same issue. But then if I left one empty line after the opening brace of method, IntelliJ didn't move entire code to one line.
For better understanding,
Problematic behavior
public void methodA(){
System.out.println("No blank line left");
}
Now when you close and open the file again, IntelliJ does this
public void methodA(){ System.out.println("No blank line left"); }
Correct Behavior
public void methodA(){
System.out.println("left a blank line above");
}
Now when you close and open the file again, it still stays like that
public void methodA(){
System.out.println("left a blank line above");
}
Just to make a note, IntelliJ version is Ultimate 14.1.4
For Webstorm - IntelliJ for Javascript, this option is in Preferences->Editor->Code Style -> Javascript-> Wrapping and Braces.
Well I have a problem with one of my classes in Eclipse. In there I define an inner Enum type.
In the picture you can see one of the enum-Constants:https: //www.dropbox.com/s/z9shh52au35mkzy/Pict1.JPG
Now I wanted to add some code to the "setup()" method. Sadly the syntax coloring for the new code doens't show up and even if I create a syntax error inside, it doesn't recognize it. (it works at other places)
https://www.dropbox.com/s/0t6que0pg1hr1tw/Pict2.JPG (can't put pictures in the question yet, I hope you don't mind if I put links there)
Finally, when I save the file and reopen it, the error behaviour is the same, but my pour code looks like this: https://www.dropbox.com/s/9lqzchv4xrnpau6/Pict3.JPG
As you can see, even in the other enum constants, there is just color at keywords and things outside of methods. (If I remove the added code and reopen, it works as if nothing hab happened)
So my question is, how can I fix this?
Thanks in advance.
First of all I'm using netbeans as my IDE and I don't know if this is causing it. When I run my program (even if I have build it and run the .jar) I think it selects the tab that was previously selected (before quiting). So if for example I close the app with the third tab selected, it starts up with that selected again. Is there a known solution for this? The selectedIndex property on the jTabbedPane is set to 0. Shouldn't this property be the default onLoad value?
Thx in advance, Jimmy
PS. BTW for some reason it didn't submit my question in Opera (?)
tabbedPaneName.setSelectedIndex(0);
just put that line in the place where the tabbed pane would be loaded
if a button actuion will load the tabbed pane then put the line there
but change tabbedPaneName to YOUR tabbed pane name.
Same problem here with Netbeans 6.8 and JTabbedPane. Neither setSelectedIndex() nor setSelectedComponent() makes a difference. The getSelectedIndex() returns the value previously set, but the pane is not selected correctly.
The reason for this is that the SingleFrameApplication saves it's state and restores the saved state on the next restart. This is done in the code generated by the GUI builder.
You could see that startup() and configureWindow() methods of the SingleFrameApplication are overridden.
Workarounds:
You could override the shutdown() method as well, then modifications to the configuration will not be saved. Note that the original will still be restored, so ensure that the required configuration is saved.
Modifying the startup() method also helps:
MyView myView = new MyView(this);
myView.getFrame().setVisible(true);
myView.getFrame().pack();
The only way it can be set to an index other than zero is if the Java code contains:
tabbedPane.setSelectedIndex(...);
So search the source code for that line and fix it.
Besides using JTabbedPane.setSelectedIndex(), it's also possible to select a tab by calling JTabbedPane.setSelectedComponent(). Have you searched the code for setSelectedComponent() as well?
I had the same problem and found an easy workaround.
In netbean's GUI-builder I set my tabbedpane to not enabled. Later in my program I checked if it was not enabled and in that case called MyTabbedPane.setEnabled(true); and MyTabbedPane.setSelectedIndex(0);
Same problem. Had to go back to NetBeans 7.0.1 to update a JSR 296 application and Java 7 runs it differently than previous versions did so the last tab created was always the one that had focus. Couldn't get anything to change that in the constructor, but finally found just wrapping the same call (setSelectedIndex()) in a call to invokeLater() solves it.
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
tabMain.setSelectedIndex(0);
}
}
);