FULL PRODUCT VERSION :
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\Owner>java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
C:\Users\Owner>
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\Owner>ver
Microsoft Windows [Version 6.3.9600]
A DESCRIPTION OF THE PROBLEM :
The StyleManager will ignore any user agent style sheets added before the initial primary stage is shown. This requires that the primary stage be shown first before the application can add a global style sheet that derives the default caspian and modena style sheets. This behavior is inconsistent and also occurs on the command line. It does not allow the user to create global style sheets or to load such style sheets during a startup splash screen. It is usually desirable to load resources prior to showing the application. This is also a known bug by the community but which is not present in the internal bug database.
http://www.guigarage.com/2013/03/global-stylesheet-for-your-javafx-application/
http://stackoverflow.com/questions/31763478/getstylesheets-add-not-working-with-windows-7
The best solution would be to create new methods for the Application class that wraps the style manager with the intended behavior such as Application.addUserAgentStyleSheet, Application.removeUserAgentStyleSheet, or Application.getStyles.add and Application.getStyles.remove
This would provide feature parity with the Qt framework where the global style sheet is set on the QApplication and derives the default style sheet.
http://doc.qt.io/qt-4.8/stylesheet-examples.html
qApp->setStyleSheet("QLineEdit { background-color: yellow }");
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a new JavaFX application and in main() or Application.launch() attempt to add a user agent style sheet before showing the primary stage.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I was expecting the StyleManager class to keep my user agent style sheet and apply it once the primary stage was shown.
ACTUAL -
The StyleManager ignored my user agent style sheet addition and did not apply it.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package helloworld;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class HelloWorld extends Application {
public static void main(String[] args) {
// does not get applied
StyleManager.getInstance().addUserAgentStylesheet("file:Default.css");
launch(args);
}
@Override
public void start(Stage primaryStage) {
// does not get applied
StyleManager.getInstance().addUserAgentStylesheet("file:Default.css");
primaryStage.setTitle("Hello World!");
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
// actually works
// StyleManager.getInstance().addUserAgentStylesheet("file:Default.css");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
A temporary work around is to keep a list of all your sheet paths and stack the user agent style sheets with StyleManager after showing your primary stage.
SUPPORT :
YES
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\Owner>java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
C:\Users\Owner>
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.
C:\Users\Owner>ver
Microsoft Windows [Version 6.3.9600]
A DESCRIPTION OF THE PROBLEM :
The StyleManager will ignore any user agent style sheets added before the initial primary stage is shown. This requires that the primary stage be shown first before the application can add a global style sheet that derives the default caspian and modena style sheets. This behavior is inconsistent and also occurs on the command line. It does not allow the user to create global style sheets or to load such style sheets during a startup splash screen. It is usually desirable to load resources prior to showing the application. This is also a known bug by the community but which is not present in the internal bug database.
http://www.guigarage.com/2013/03/global-stylesheet-for-your-javafx-application/
http://stackoverflow.com/questions/31763478/getstylesheets-add-not-working-with-windows-7
The best solution would be to create new methods for the Application class that wraps the style manager with the intended behavior such as Application.addUserAgentStyleSheet, Application.removeUserAgentStyleSheet, or Application.getStyles.add and Application.getStyles.remove
This would provide feature parity with the Qt framework where the global style sheet is set on the QApplication and derives the default style sheet.
http://doc.qt.io/qt-4.8/stylesheet-examples.html
qApp->setStyleSheet("QLineEdit { background-color: yellow }");
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a new JavaFX application and in main() or Application.launch() attempt to add a user agent style sheet before showing the primary stage.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I was expecting the StyleManager class to keep my user agent style sheet and apply it once the primary stage was shown.
ACTUAL -
The StyleManager ignored my user agent style sheet addition and did not apply it.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package helloworld;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class HelloWorld extends Application {
public static void main(String[] args) {
// does not get applied
StyleManager.getInstance().addUserAgentStylesheet("file:Default.css");
launch(args);
}
@Override
public void start(Stage primaryStage) {
// does not get applied
StyleManager.getInstance().addUserAgentStylesheet("file:Default.css");
primaryStage.setTitle("Hello World!");
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
// actually works
// StyleManager.getInstance().addUserAgentStylesheet("file:Default.css");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
A temporary work around is to keep a list of all your sheet paths and stack the user agent style sheets with StyleManager after showing your primary stage.
SUPPORT :
YES