Why Run button of IDEA (green triangle) runs not current code opened on the screen, but previous?
Run button of the IDEA
You must be signed in to leave a comment
16 September 2020, 14:44
You're right, by default IDEA runs the last configuration and not the file you have currently open/active in your editor. This can be annoying for beginners like us who have only a few files and basically all of them are runnable classes with a main method. But consider the other way around: You are working on a larger program, currently editing some data or config-file. Then you hit "run" and IDEA would - instead of running your main-method, try to execute the data file you are working on. There are, however, a few convenient ways to run the currently open file: 1. Right click anywhere in your currently open file that you want to run and select the run-option from the context menu 2. The keyboard shortcut for running the last configuration (same thing as the run-button does) is SHIFT+F10, the shortcut for running the currently active file is CTRL+SHIFT+F10. (This may be different on your machine, depending on the operating system etc., but you can manually configure the keyboard shortcuts) Happy coding anyway!
17 September 2020, 06:15
Thank you for the detailed explanation!! But I still think that IDEA could see that there's the main method in the current (opened and active) code and I want to run it. May be there's an option to put such a button on the toolbar?
17 September 2020, 11:17
If you want, you can definitely add a button for that to the menu. Simply go to File -> Settings -> Appearance & Behaviour -> Menus and Toolbars. (Btw this is the place where you can customize basically every menu you encounter in IDEA). Then choose the menu you want this button to appear in - for example, the "Navigation Bar Toolbar" at the top where the CodeGym-buttons are. Click on the little "+"-icon at the top next to the search bar, and chose "Add action...". The action you are looking for - running the currently open file - is called "Run context configuration".
18 September 2020, 04:12
Thank you, once again!