Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to adjust row spacing #862

Closed
yanzhao77 opened this issue Nov 6, 2019 · 6 comments · Fixed by #865
Closed

How to adjust row spacing #862

yanzhao77 opened this issue Nov 6, 2019 · 6 comments · Fixed by #865

Comments

@yanzhao77
Copy link

yanzhao77 commented Nov 6, 2019

No description provided.

@Jugen
Copy link
Collaborator

Jugen commented Nov 6, 2019

You can specify line spacing with CSS like so:

.paragraph-text {
    -fx-line-spacing: 15;
}

@yanzhao77
Copy link
Author

yanzhao77 commented Nov 7, 2019

I tried to do that, but it didn't seem to work. Did I set it up wrong

~~o(>_<)o ~~
this is my code

package test;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.InlineCssTextArea;

public class consoleText1 extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane anchorPane = new AnchorPane();
        InlineCssTextArea textArea = new InlineCssTextArea();
        VirtualizedScrollPane virtualizedScrollPane=new VirtualizedScrollPane(textArea);
        anchorPane.setTopAnchor(virtualizedScrollPane, 0.0);
        anchorPane.setBottomAnchor(virtualizedScrollPane, 0.0);
        anchorPane.setLeftAnchor(virtualizedScrollPane, 0.0);
        anchorPane.setRightAnchor(virtualizedScrollPane, 0.0);

        textArea.setStyle(" -fx-line-spacing: 15");

        anchorPane.getChildren().add(virtualizedScrollPane);
        Scene scene = new Scene(anchorPane, 500, 600);
        primaryStage.setScene(scene);
        primaryStage.setTitle("test");
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

@Jugen
Copy link
Collaborator

Jugen commented Nov 7, 2019

Unfortunately it doesn't work with setStyle, it has to be added through a stylesheet like:

scene.getStylesheets().add( "path-to/my-style-sheet.css" );

@yanzhao77
Copy link
Author

yanzhao77 commented Nov 8, 2019

wo,It's a bit awkward, or it's a failure. No matter how I adjust, the spacing between each line is still so large

package test;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.InlineCssTextArea;

public class consoleText1 extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane anchorPane = new AnchorPane();
        InlineCssTextArea textArea = new InlineCssTextArea();
        VirtualizedScrollPane virtualizedScrollPane=new VirtualizedScrollPane(textArea);
        anchorPane.setTopAnchor(virtualizedScrollPane, 0.0);
        anchorPane.setBottomAnchor(virtualizedScrollPane, 0.0);
        anchorPane.setLeftAnchor(virtualizedScrollPane, 0.0);
        anchorPane.setRightAnchor(virtualizedScrollPane, 0.0);

//        textArea.setStyle(" -fx-line-spacing: 15");

        anchorPane.getChildren().add(virtualizedScrollPane);
        Scene scene = new Scene(anchorPane, 500, 600);
        scene.getStylesheets().add( "path-to/my-style-sheet.css" );
        primaryStage.setScene(scene);
        primaryStage.setTitle("test");
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

my-style-sheet.css

.paragraph-text {
    -fx-line-spacing: 100;
}

微信图片_20191108110330

@Jugen
Copy link
Collaborator

Jugen commented Nov 8, 2019

It only applies to lines inside a paragraph that wraps over multiple lines and not between paragraphs that only have one line. In RichTextFX a paragraph is any text that ends with enter / new line.

In the image you provided it looks like each line ends with enter without wrapping and so no line-spacing is seen.

I suppose this is an oversight since if you have for example a numbered or bulleted list of single lines then one would expect the list to have the same spacing as a multi-lined wrapped paragraph. I'll have a look and see if I can change it.

@Jugen
Copy link
Collaborator

Jugen commented Nov 8, 2019

You can also try the following CSS to achieve what you want:

.paragraph-box {
    -fx-padding: 0 0 15 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants