org.fxmisc.richtext.demo.ManualHighlighting Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of richtextfx Show documentation
Show all versions of richtextfx Show documentation
FX-Text-Area for formatted text and other special effects.
package org.fxmisc.richtext.demo;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.IndexRange;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.StyleClassedTextArea;
/**
* Name: ManualHighlighting
* Description: .
*
* Comment: ...
*
* Copyright: Copyright (c) 2016-2019
* Company: >StA-Soft<
* @author StA
* @version 1.0
*/
public class ManualHighlighting extends Application
{
/**
* Main-Methode.
* @param args Kommandozeilenparameter
*/
public static void main(String[] args)
{
launch(args);
}
/**
* Area.
*/
private final StyleClassedTextArea area = new StyleClassedTextArea();
@Override
public void start(Stage primaryStage)
{
Button red = createColorButton(Color.RED, "red");
Button green = createColorButton(Color.GREEN, "green");
Button blue = createColorButton(Color.BLUE, "blue");
Button bold = createBoldButton("bold");
HBox panel = new HBox(red, green, blue, bold);
VirtualizedScrollPane vsPane = new VirtualizedScrollPane<>(area);
VBox.setVgrow(vsPane, Priority.ALWAYS);
area.setWrapText(true);
VBox vbox = new VBox(panel, vsPane);
Scene scene = new Scene(vbox, 600, 400);
scene.getStylesheets().add(ManualHighlighting.class.getResource("manual-highlighting.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("Manual Highlighting Demo");
primaryStage.show();
area.requestFocus();
}
/**
* Create bold button.
* @param styleClass style class
* @return bold button
*/
private Button createBoldButton(String styleClass)
{
Button button = new Button("B");
button.styleProperty().set("-fx-font-weight: bold;");
setPushHandler(button, styleClass);
return button;
}
/**
* Create color button.
* @param color color
* @param styleClass style class
* @return color button
*/
private Button createColorButton(Color color, String styleClass)
{
Rectangle rect = new Rectangle(20, 20, color);
Button button = new Button(null, rect);
setPushHandler(button, styleClass);
return button;
}
/**
* Set push handler.
* @param button button
* @param styleClass style class
*/
private void setPushHandler(Button button, String styleClass)
{
button.onActionProperty().set(new EventHandler()
{
@Override
public void handle(ActionEvent evt)
{
IndexRange range = area.getSelection();
area.setStyleClass(range.getStart(), range.getEnd(), styleClass);
area.requestFocus();
}
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy