0

I have a project were i used custom icons for botton and other options for the look (inspired from tutorial on youtube). I know that launching the project using a Main.java class will generate a jar file that i need.(i use in the Main.java new PrincipalFrame().setVisible(true); ) What i don't understand is why the look of the application is different from when i use the run (left cursor then run ) the run gives me the design i did on the designer view on netbeans but the main gives me (what i feel) a basic or standard view (like win98).

Please help me

that an image when i use the Maincall the Main by the code of setVisible that the image of when i use runenter image description here

  • Some part of your code is either setting the look and feel or the system is using a default look and feel – MadProgrammer Dec 27 '14 at 21:02
  • @MadProgrammer i cant answer what i don't know exactly in order to not give you a false idea so what i know that i worked with the developer tools (properties , layouts) what i can tel you if my buttons are using an imageicon it should work like my background label in the two cases (the background is normal in the two cases) that why i m a little lost in my head. – Mohammed Housseyn Taleb Dec 27 '14 at 21:14
  • 2
    We can't answer questions about code without a [runnable example](https://stackoverflow.com/help/mcve) which demonstrates your problem. This will result in less confusion and better responses – MadProgrammer Dec 27 '14 at 21:21
  • it is impossible i have more than 3000 line code whit other classes of 200 to 400 it takes me months to do this... sorry i see that is helpless – Mohammed Housseyn Taleb Dec 27 '14 at 21:33
  • 1
    I would "guess" that you have two "main" classes, the one you're running and the one the jar is running – MadProgrammer Dec 27 '14 at 23:17
  • Check the [manifest](http://stackoverflow.com/a/2201870/230513) to be sure. – trashgod Dec 27 '14 at 23:18
  • @MohammedHousseynTaleb what do you mean by `when i use the Main` ? – Madhawa Priyashantha Dec 28 '14 at 00:34
  • @FastSnail i hava Main.java class which contain new Principalframe().setvisible(true); when i run this main i got the first design but when i run the PrincipalFrame from the netbeans project viewer it gives the second one – Mohammed Housseyn Taleb Dec 28 '14 at 10:09
  • 1
    @MohammedHousseynTaleb netbean set look and feel to nimbus .if you view main method in netbeans you will see look and feel [folded].click + mark and see .you can set it then both will look same .your first one has metal look and feel 2nd frame has nimbus that's the difference – Madhawa Priyashantha Dec 28 '14 at 10:22

1 Answers1

1

your first jframe use metal look and feel and second frame use nimbus look and feel .read more about look and feel

when you run from netbeans ,netbeans set look and feel to nimbus automatically .if you inspect main method there is a code like that .

enter image description here

if you click + mark you will see codes like


enter image description here

in your question first frame looks [like win98] because you haven't set look and feel and it use default look and feel metal .

so when you run without netbeans all you need to do is set look and feel to nimbus in main method

change this

public static void main(String args[]) {

     new PrincipalFrame().setVisible(true); // metal L&f

}

to following

public static void main(String args[]) {
    try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {


               if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
               }
            }
    } catch (Exception ex) {
               ex.printStackTrace();
    }

    new PrincipalFrame().setVisible(true); // now you have set nimbus L&f

}

but when you set look and feel it's better to catch exception separately .then you can copy from netbeans main method and paste your main method .this is better way to do it

Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60