java - Why i am i getting different results at different computers, with jpanel? -
i wrote program using java, , jpanel. im getting different results(colors, borders...) in different operating systems(windows xp, mac osx). why that?
windows , osx have different themes. since use default lookandfeel different view.
try com.sun.java.swing.plaf.nimbus.nimbuslookandfeel
as side note can use followed class changes style based on os.
it not support osx sure, can modify it.
public final class common { // ------------------------------ constants ------------------------------ private static final boolean debugging = false; // -------------------------- public static methods -------------------------- /** * set , feel swing app, based on os , jdk version.. */ public static void setlaf(){ //"com.sun.java.swing.plaf.nimbus.nimbuslookandfeel" //"com.sun.java.swing.plaf.windows.windowslookandfeel" if ( setlaf( null, 1, 6, 0, "com.sun.java.swing.plaf.windows.windowslookandfeel" ) ) { // won't take less 1.6.0_10 return; } if ( setlaf( "windows vista", 1, 3, 0, uimanager.getcrossplatformlookandfeelclassname() ) ) { return; } if ( setlaf( "windows xp", 1, 3, 0, uimanager.getcrossplatformlookandfeelclassname() ) ) { return; } setlaf( null, 1, 3, 0, uimanager.getsystemlookandfeelclassname() ); // if failed, give up. leave original l&f in place. } /** * set , feel swing app, based on os , jdk version.. */ public static void setlafnim(){ //"com.sun.java.swing.plaf.nimbus.nimbuslookandfeel" //"com.sun.java.swing.plaf.windows.windowslookandfeel" if ( setlaf( null, 1, 6, 0, "com.sun.java.swing.plaf.nimbus.nimbuslookandfeel" ) ) { // won't take less 1.6.0_10 return; } if ( setlaf( "windows vista", 1, 3, 0, uimanager.getcrossplatformlookandfeelclassname() ) ) { return; } if ( setlaf( "windows xp", 1, 3, 0, uimanager.getcrossplatformlookandfeelclassname() ) ) { return; } setlaf( null, 1, 3, 0, uimanager.getsystemlookandfeelclassname() ); // if failed, give up. leave original l&f in place. } // -------------------------- static methods -------------------------- /** * attempt set laf, depending on os , jdk being suitable. * * @param os name of os, null means not matter. * @param wantedmajor java major version e.g. 1 * @param wantedminor java minor version e.g. 6 * @param wantedbugfix java bugfix version e.g. 14 * @param lafclassname class name of laf set if os matches , jdk version sufficiently advanced. * * @return true setting took, false if failed. */ private static boolean setlaf( string os, int wantedmajor, int wantedminor, int wantedbugfix, string lafclassname ) { if ( os != null && !system.getproperty( "os.name", "unknown" ).equals( os ) ) { return false; } try { uimanager.setlookandfeel( lafclassname ); } catch ( unsupportedlookandfeelexception e ) { if ( debugging ) { system.err.println( "fail: unsupportedlookandfeelexception" + lafclassname + e.getmessage() ); } return false; } catch ( illegalaccessexception e ) { if ( debugging ) { system.err.println( "fail: illegalaccessexception" + lafclassname + e.getmessage() ); } return false; } catch ( instantiationexception e ) { if ( debugging ) { system.err.println( "fail: instantiationexception" + lafclassname + e.getmessage() ); } return false; } catch ( classnotfoundexception e ) { if ( debugging ) { system.err.println( "fail: classnotfoundexception" + lafclassname + e.getmessage() ); } return false; } catch ( exception e ) { if ( debugging ) { system.err.println( "fail: exception" + lafclassname + e.getmessage() ); } return false; } if ( debugging ) { system.err.println( "choosing l&f " + lafclassname ); } return true; } }
Comments
Post a Comment