I have a large class that contains about 30 methods. Is it possible to automatically sort them in alphabetical order in eclipse? I was hoping to do this so they would be easier to find when java browsing or looking at the class outline window.
If you just want to view your class members in sorted order without modifying the code then you can click on the A/Z icon on the outline view, as others have pointed out. Alternatively, you may wish to sort the class members in the code itself, in which case you should right click your source or source file name to get the context sensitive menu, then select Source(Alt-Shift-S), Sort Members.
It will pop up a dialog box allowing you to customize the sort, choose your desired options and click ok.
You can actually sort members of your class in your code with eclipse, in my opinion this improves readability but should be used with caution.
select the class, Source > Sort Members
Thanks to marcggs' answer.
Press the Sort button in the Outline view. It has A, Z, and an arrow in it.
I wouldn't modify the Java source if I were you. If you're using an IDE such as Eclipse, then this adds no benefit, and there are a few costs, including:
If the code already is checked in to source control, then resorting it can break the history
I've never heard of a group with a coding convention of sorting methods alphabetically
You can use the alphabetic sort in the overview window for this.
icon
Related
Is there a way to just see one method of a class in the IntelliJ IDEA editor and hide everything else, and/or toggle between this and the regular view.
Please note, I'm not looking to fold/collapse other methods, which is certainly a way to minimize getting lost in a large file.
I am looking for a way to only view a specific method I'm working on within a class.
e.g. If there is a legacy code where an existing class has 10 long
methods (each ~50 lines long), and I'm working on one of them and don't wish to be lost in
the 500 lines of code and need to focus on a single method thereby narrowing my view to 50
lines of code.
I do remember a few versions back that this was possible, but am not able to find that setting now.
Further clarifying my question. Consider the method selected in the image below
I am interested in a view that'll show just the method like below (with all the java capabilities like code highlighting, refactoring etc., enabled of course):
In IntelliJ IDEA 2019.3.3 (Community Edition) there's a fold option 'Fold Selection' that hides even the signature.
Select / highlight the code above the method you want to focus on
Right click > Folding > Fold Selection. Shortcut = cmd + .
It might be in earlier versions but I haven't checked.
Fold selection menu option
I am new to Java and I am working on a project where depending on number of files in a directory,
buttons will be created respectively. Each button will have a customized right click context menu.
How can I achieve this or is this feasible?
I just want to know the approach to do this.
The approach that you may try:
While you iterate your directory/file list (or other process that will determine the button creation), you can generate (create an instance of) a new button (JButton), I assume you know how to use new, and put it on your form / panel.
However, most of the time, layout would become an annoying issue here.
Thus, you may try to use MigLayout to handle this.
It will help you a lot in putting your stuffs in a tidy and convenient way.
Try this approach and when you have a specific coding-part question, you can try to search the existing solution in SO (StackOverflow) or if it doesn't exist, you can ask that specific code-related question.
Hope it helps.
I need to rearrange some files according to same style. There are many "getters and setters" in random places. I want to move them to the bottom of file and sort by name.
Is any plugin or something to do this?
Intellij gives you the option to automatically rearrange your code in the way that you prefer.
You can first go to Settings->Code Style->Java to choose the format of your code, and after that just hit Code->Rearrange Code.
For more information check these:
Rearrange code Official docs
Rearrange you code
I think the fastest way is to drag the methods in the outline section of eclipse
If they are simple getters and setters, then you can delete the ones you have right now and then recreate them by groups.
So, after you delete them, place caret below all class members and press Alt + Insert on your keyboard, then choose Getter and Setter and then select member you want to create in the first batch. After that, place the caret to the end of a file and repeat the steps.
This is how I do in cases when I have pure getters and setters.
Hi am creating an application in which I am using JTable to listing of file or folder names.
My question is:
How can I find and Search a Particular file or folder in JTable like in Windows.
In windows directory listing when we press any key then we can see that file or folder start with that character is selected and if we again press same key then next file/folder is selected with start with that character.
If you can use 3th party code, I would suggest to take a look at the SwingX project. Their JXTable, JXTree, JXList and some other classes provide an implementation of the Searchable interface, which makes creating a search widget a breeze.
And if that is even too difficult, they provide out-of-the-box a JXFindPanel which provides a UI to search a Searchable
If you can (and you're willing to) use third party UI components, the Open Source JIDE Common Layer offers a few nice components: e.g. you might like FolderChooser which has an automatic find-as-you-type functionality.
Here's the link: JIDE Common Layer. If you click the "RUN IT" button you can see a sample via Java Web Start.
I've used many JIDE components (only the open source ones) in my projects and avoided reinventing the wheel many times.
Hope this might help you.
You want an action happen when a key is typed ?
-> add a keyListener to your table
You want to know which row is valid
-> query your datamodel connected to your jtable
You want a selected row to change ?
-> in the keytyped implementation of your listener change the selection
table.getSelectionModel().setSelectionInterval(1,1);
Since I don't know something about how did you implement your code logics, JTable implemented Sorting and Filtering
but you describtions talking about JTreeTable
I would consider writing a custom TableCellRenderer, responsible for highlighting any matching letters in the String being rendered. When someone updates the search text field the simplest approach is going to then be to repaint the entire JTable to show the updated "match state" of the table cells.
I need to make an expandable list using java swing. I will attempt to demonstrate:
Unexpanded:
>[Expand me!]
>[And me!]
Expanded:
|[Expand me!]
>[Expand us too!]
>[Expand us too!]
>[Expand us too!]
>[And me!]
So, when you click on the "Expand me" portion of the list, another lists will drop down, possibly containing more expandable lists. If you were to click on it again, it's "sub-lists" would then retract. Pretty basic. And, as you can see, I am not looking for JComboBox, and I do not think JList can do this. If someone were to point me in the right direction, or give some programming examples, I would be grateful.
Thanks,
MirroredFate
How about using a JTree.
A control that displays a set of hierarchical data as an outline.
You can try using a JTable and put a button in the first column. When the button is clicked you add more data in the rows in between.
update
Something like this:
Or this
I think the first uses a JTree but that the idea.
BTW these two belong to JIDE Soft, check if it is feasible for you to buy a license:
http://www.jidesoft.com/products/grids.htm
Is not trivial to roll you own but is not impossible either.
check for TreeTable or one example or Outline, but with notice, that on official Java (SnOracle) pages any progress died ...,