How to customize a HTML Editor - css

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.

Related

How to make a suttering window in JavaFx?

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);
}
}

Javafx HtmlEditor: preview color is so small

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);
}
}

Simple way to create a vertical ButtonBar using JavaFX Scene Builder/Gluon

How do I make a vertical ButtonBar in JavaFX 8?
I want exactly the same concepts of the ButtonBar component, but ButtonBar is horizontal, I want vertical. All the buttons must be same size.
If I use a VBox I have to set the width of the buttons and of the VBox manually.
Is there a simpler way to do that without having to set widths?
You need two things: to set fillWidth to true on the VBox, and to set maxWidth on each button. The most convenient approach is probably a simple subclass of VBox:
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
public class VerticalButtonBar extends VBox {
public VerticalButtonBar() {
setFillWidth(true);
}
public void addButton(Button button) {
button.setMaxWidth(Double.MAX_VALUE);
getChildren().add(button);
}
}
and then you can do things like
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class VerticalButtonBarExample extends Application {
#Override
public void start(Stage primaryStage) {
VerticalButtonBar bar = new VerticalButtonBar();
bar.addButton(new Button("A"));
bar.addButton(new Button("Button"));
BorderPane root = new BorderPane();
root.setLeft(bar);
primaryStage.setScene(new Scene(root, 400, 400));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
which looks like
See Adding a custom component to SceneBuilder 2.0 if you want to make the VerticalButtonBar visible to SceneBuilder.
As far as I can see, ButtonBar has no way to change this, so there is nothing SceneBuilder can do about it.
You might want to file a feature request for ButtonBar: http://bugs.java.com/

javafx 8 create images on button on hover using css

I'm making a Mario themed application, and I would like the buttons to have the effect that when the user hovers over it with his/her mouse, a mushroom (image) appears next to the text of the button, and disappears when the mouse moves away.I'm trying to do this using css.
How can one do this?
Use the hover pseudoclasses.
.button:hover{
-fx-graphic: url('your_path_to_image');
}
Complete Example
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
public class Main extends Application {
public void start(Stage primaryStage) {
Button button = new Button("Click");
HBox container = new HBox(button);
container.setAlignment(Pos.CENTER);
Scene scene = new Scene(container, 200, 200);
scene.getStylesheets().add(getClass().getResource("/style.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
style.css
.button:hover{
-fx-graphic: url('http://files.softicons.com/download/game-icons/super-mario-icons-by-sandro-pereira/png/16/Mushroom%20-%201UP.png');
}
Image
On hover

Select text from GridPane

I have this very simple example of GridPane.
GridPane playerGrid = new GridPane();
Text title = new Text("Top Scorers in English Premier League");
title.setFont(Font.font("Arial", FontWeight.BOLD, 20));
playerGrid.add(title, 0,0,4,1);
How I can select the text with the mouse and copy it when the program is running?
Text nodes in JavaFX are not selectable.
If you want to have text selectable, use a selection aware control.
The fact that the text is eventually placed in a GridPane is irrelevant to this question.
For example, use a read only TextField:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
public class SelectableTextSample extends Application {
#Override public void start(final Stage stage) throws Exception {
stage.setScene(
new Scene(
new SelectableText(
"Top Scorers in English Premier League"
)
)
);
stage.show();
}
class SelectableText extends TextField {
SelectableText(String text) {
super(text);
setEditable(false);
setPrefColumnCount(20);
}
}
public static void main(String[] args) {
Application.launch(args);
}
}
Alternate solution
You could use a WebView if you wish. For some situations that may be a better solution, but for others it may not.

Resources