GithubHelp home page GithubHelp logo

Comments (8)

DevCharly avatar DevCharly commented on August 21, 2024 1

Tried also this solution in FlatLaf some days ago. This had some downsides. First was that FlatLaf.uninitialize() was invoked from within FlatLaf.initialize(). See stack trace:

Thread [AWT-EventQueue-0] (Suspended (breakpoint at line 165 in FlatLaf))	
	FlatLightLaf(FlatLaf).uninitialize() line: 165	
	UIManager.setLookAndFeel(LookAndFeel) line: 580	
	UIManager.setLookAndFeel(String) line: 633	
	FlatLightLaf(FlatLaf).getBase() line: 197	
	FlatLightLaf(FlatLaf).initialize() line: 115	
	UIManager.setLookAndFeel(LookAndFeel) line: 586	
	UIManager.setLookAndFeel(String) line: 633	
	DemoPrefs.initLaf(String[]) line: 69	
	FlatTestFrame.create(String[], String) line: 75	
...

Next problem was that the active LaF (UIManager.getLookAndFeel()) remains AquaLookAndFeel, but with UI default values from FlatLaf. This was a mess...

But there is a better solution. Since Java 9 there is a new method UIManager.createLookAndFeel(String) that allows creating installed LaFs by name.

This is what I'm using in FlatLaf now:

if( SystemInfo.IS_JAVA_9_OR_LATER ) {
    Method m = UIManager.class.getMethod( "createLookAndFeel", String.class );
    base = (BasicLookAndFeel) m.invoke( null, "Mac OS X" );
} else {
    base = (BasicLookAndFeel) Class.forName( UIManager.getSystemLookAndFeelClassName() ).newInstance();
}

This works fine without any warning.

BTW congrats to the great DarkLaf launch. 👍
Glad that you decided to continue DarkLaf. Swing needs good modern up-to-date LaFs. The more the better. And many thanks for mentioning FlatLaf in your reddit announcement.

from darklaf.

weisJ avatar weisJ commented on August 21, 2024

Shouldn't occur anymore.

from darklaf.

vlsi avatar vlsi commented on August 21, 2024

I'm not sure how often Jigsaw is used, however, I guess that would be an error in a modular application.

What do you think of getting the instance via UIManager.getLookAndFeel()?

from darklaf.

vlsi avatar vlsi commented on August 21, 2024

For instance:

final String systemLafClassName = UIManager.getSystemLookAndFeelClassName();
final LookAndFeel currentLaf = UIManager.getLookAndFeel();
if (systemLafClassName.equals(currentLaf.getClass().getName())) {
    if (currentLaf instanceof BasicLookAndFeel) {
        base = (BasicLookAndFeel) currentLaf;
    } else {
        base = new MetalLookAndFeel();
    }
} else {
   // Here can be a dance with UIManager.setLookAndFeel(systemLafClassName) + getLookAndFeel

    try (ReflectiveWarningSuppressor sup = new ReflectiveWarningSuppressor()) {
        final String name = UIManager.getSystemLookAndFeelClassName();
        base = (BasicLookAndFeel) Class.forName(name).getDeclaredConstructor().newInstance();
    }
}

from darklaf.

weisJ avatar weisJ commented on August 21, 2024

Yes this looks like a good solution. If --illegal-access=deny is used the current LaF could still be used as a fallback option with a warning that the LaF might not behave as intended.

from darklaf.

vlsi avatar vlsi commented on August 21, 2024

the current LaF

What I mean is the following sequence seems to comply with --illegal-access=deny:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
LookAndFeel systemLaf = UIManager.getLookAndFeel();

from darklaf.

weisJ avatar weisJ commented on August 21, 2024

Though a rather heavy operation probably the best solution. I checked the implementation of UIManager and changing the Laf inside the constructor doesn't interfere with the Laf installation.

from darklaf.

weisJ avatar weisJ commented on August 21, 2024

Thanks for the insight. Though the issue you are describing stems from initializing the base laf in LookAndFeel#initalize. Here the base laf is created in the constructor of DarkLaf, so it actually happens before initialize has been called.

BTW congrats to the great DarkLaf launch. 👍
Glad that you decided to continue DarkLaf. Swing needs good modern up-to-date LaFs.
The more the better. And many thanks for mentioning FlatLaf in your reddit announcement.

Thank you for the kind words :)

from darklaf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.