I want to put a background image into a scene but I always get an error message
PM com.sun.javafx.css.parser.CSSParser parse and
WARNING: CSS Error parsing file:/D:/Login/bin/login/Login.css: Expected LBRACE at [1,9]
Here is a SSCE from my Login.java:
package login;
import javafx.application.Application;
import javafx.geometry.*;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class Login extends Application {
#Override
public void start(Stage primaryStage) {
primaryStage.setTitle("JavaFX Welcome");
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
Scene scene = new Scene(grid, 300, 275);
scene.getStylesheets().add(Login.class.getResource("Login.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
And here is my a CSS from my Login.css
#CHARSET "ISO-8859-1";
.root {
-fx-background-image: url("background.jpg");
}
Does it have to do with my current plugin? I use eclipse Luna and the WTP toolkit to work with style sheets.
Many thanks!
The CSS parser in recent JavaFX versions seems to choke on the #CHARSET declarations. If you remove that declaration, it should fix the problem.
Related
Try creating a JavaFX application.
Don't add or modify any code.
Run the Project. It does not find the MAIN.
If you run the File, then it works.
However, create JavaFX FXML application. As mentioned earlier, don't make any change to the code.
Run the Package.... it WORKS.
Does anyone know why? I tried to report the problem, but that looked more complicated than writing the code. :)
I am enclosing generated code for a JAVAFX APPLICATION
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package forsubmission;
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;
/**
*
* #author Hornigold
*/
public class ForSubmission extends Application {
#Override
public void start(Stage primaryStage) {
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);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Thanks,
Gold
I need a window that can be move up down in my main window. Mainly IDE(IntelliJ, CodeBlock, Netbeans etc) output window feature.
I use TitledPane. By using this I can give a height that is expanded when I click the pane, but I can't expand the pane in any height.
see this - not expanded:
and this- expanded:
My code is here
Try using SplitPane. I guess this is what you want. You can learn more from the following link
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/SplitPane.html
import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
SplitPane splitPane = new SplitPane(new Pane(), new Pane());
splitPane.setDividerPositions(0.5);
splitPane.setOrientation(Orientation.VERTICAL);
primaryStage.setScene(new Scene(splitPane,400,400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
In HTMLEditor of JavaFX: the preview color is so small.
I want to show bigger like picture below:
How i can do.
Thanks
The style of the HTMLEditor is customized via CSS.
.html-editor-foreground {
-fx-color-rect-width: 16;
-fx-color-rect-height: 16;
-fx-graphic: null;
}
Here we style the foreground color picker picked color indicator as a (relatively) large rectangle (with a pink color chosen for the sample):
Sample Code
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;
public class EditorSample extends Application {
#Override
public void start(Stage stage) throws Exception {
HTMLEditor editor = new HTMLEditor();
Scene scene = new Scene(editor);
scene.getStylesheets().add(
this.getClass().getResource(
"html-editor-large-color-rect.css"
).toExternalForm()
);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
How can I go about changing the background color of the text input area in a HTML Editor in JavaFX?
Set the text of the html editor, specifying the appropriate background color in a style.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;
public class ColoredBackground extends Application {
#Override
public void start(Stage stage) {
HTMLEditor editor = new HTMLEditor();
editor.setHtmlText("<body style='background-color: papayawhip;'/>");
stage.setScene(new Scene(editor));
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I don't believe this is possible. Drilling down into HTMLEditorSkin shows that the 'text input area' of the HTMLEditor is a WebView, which doesn't seem to contain a CSSMetaData entry for styling.
Consider this sample program which is adding a TabPane into an Alert. As you will see, there is a white padding on the left of the TabPane that I just cannot remove.
If anyone has any idea it will be great.
Code:
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class AlertTest extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(new HBox());
primaryStage.setScene(scene);
primaryStage.show();
Alert alert = new Alert(Alert.AlertType.NONE);
alert.setTitle("");
alert.initOwner(primaryStage);
TabPane tabPane = new TabPane(new Tab("test"));
tabPane.setPadding(Insets.EMPTY);
alert.getDialogPane().setPadding(Insets.EMPTY);
alert.getDialogPane().setContent(tabPane);
alert.show();
}
}
Visual :
If you add css like this:
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(new HBox());
primaryStage.setScene(scene);
//add this 3 lines
String css = Main.class.getResource("styles.css").toExternalForm();
scene.getStylesheets().clear();
scene.getStylesheets().add(css);
...
}
and in styles.css add
.dialog-pane:no-header .graphic-container {
-fx-padding: 0; /* 10px 0px 0px 10px */
}
You can find more info about the default styles in file: fxrt.jar!/com/sun/javafx/scene/control/skin/modena/modena.css
and here is the result and full code demo: