JPro-one / JPro

The right place to report about bugs or suggest improvements for JPro.
https://www.jpro.one
9 stars 4 forks source link

JavaFx TitledPane's -> title Text warp not works fine e.g. w.r.t height! #147

Closed ctoabidmaqbool closed 1 year ago

ctoabidmaqbool commented 1 year ago

Hi! I am making FAQ's page in JPro. I am using TitlePane for this purpose. But It's have issue of Text wrapping, is any solutions there???

image

Expected behavior, The Title bar of TitlePane should be auto resize (e.g. w.r.t. Height) as of (HTML) when there is not enough width and text is large then width.

  private VBox getNode() {
        VBox root = new VBox();

        TitledPane titledPane1 = new TitledPane();
        titledPane1.setMinWidth(100);
        titledPane1.setPrefWidth(100);
        titledPane1.setMaxWidth(100);

        Label lbl1 = new Label("5 sample paragraphs for reading test on 1. Traveling in a D. T. C. Bus  2. Look Before You Leap 3. Rising Prices 4. ‘Simple Living, High Thinking’ 5. A Football Match");
        lbl1.setWrapText(true);

        titledPane1.setGraphic(lbl1);

        Label lbl11 = new Label("Delhi is a crowded city. There are very few rich people who travel by their own vehicles. The majority of the people cannot afford to hire a taxi or a three-wheeler. They have to depend on D.T.C. buses, which are the cheapest mode of conveyance.");
        lbl11.setWrapText(true);

        titledPane1.setContent(new VBox(lbl11));

        // OR

        TitledPane titledPane2 = new TitledPane();
        titledPane2.setText("5 sample paragraphs for reading test on 1. Traveling in a D. T. C. Bus  2. Look Before You Leap 3. Rising Prices 4. ‘Simple Living, High Thinking’ 5. A Football Match");
        titledPane2.setMinWidth(100);
        titledPane2.setPrefWidth(100);
        titledPane2.setMaxWidth(100);

        Label lbl12 = new Label("Delhi is a crowded city. There are very few rich people who travel by their own vehicles. The majority of the people cannot afford to hire a taxi or a three-wheeler. They have to depend on D.T.C. buses, which are the cheapest mode of conveyance.");
        lbl12.setWrapText(true);

        titledPane2.setContent(new VBox(lbl12));

        root.getChildren().addAll(titledPane1, titledPane2);

        return root;
    }

I know it's Javafx Issue not JPro. However any solutions?

FlorianKirmaier commented 1 year ago

I guess you could try setting wrap-text with CSS. Our can even use scenic-view and check whether setting wrap-text results in the wanted behaviour.

ctoabidmaqbool commented 1 year ago

I guess you could try setting wrap-text with CSS. Our can even use scenic-view and check whether setting wrap-text results in the wanted behaviour.

I have tried using CSS way too! Even test quickly using Scene Builder (CSS Analyzer) and Scenic View too.

We can simply set absolute height to titled>pane{} but USE_COMPUTED_SIZE not works e.g. -1.

I want that height should be auto computed w.r.t text wrapping. If height of title is large enough then wrapping works well. But height not auto computed.

FlorianKirmaier commented 1 year ago

I guess you always have the option to write your own control.

ctoabidmaqbool commented 1 year ago

Yes, making custom control is a complex and time consuming task.

I also try using vlookup way to get Title element and then setting pref height.

In short, i try every possibility but still the problem not solved.

I am still working on this, maybe any trick works!

ctoabidmaqbool commented 1 year ago

Something like this codding I have tried, that too not works!

 Platform.runLater(() -> {
       StackPane title = (StackPane) titledPane1.lookup(".title");
       title.setMinSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
       title.setPrefWidth(100);
       title.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);

       title.prefHeightProperty().bind(lbl1.prefHeightProperty());
});
ctoabidmaqbool commented 1 year ago

@FlorianKirmaier Okey! I have solved the above issues myself, by using something like this codding:

 private Node getView() {
        StackPane root = new StackPane();

        TitledPane titledPane2 = new TitledPane();
        titledPane2.setMinWidth(Region.USE_PREF_SIZE);
        titledPane2.setPrefWidth(400);
        titledPane2.setMaxWidth(Region.USE_PREF_SIZE);
        titledPane2.setAlignment(Pos.TOP_LEFT);

        Label lbl1 = new Label(
                "5 sample paragraphs for reading test on 1. Traveling in a D. T. C. Bus  2. Look Before You Leap 3. Rising Prices 4. ‘Simple Living, High Thinking’ 5. A Football Match");
        lbl1.setWrapText(true);
        lbl1.setMinHeight(Region.USE_PREF_SIZE);
        lbl1.setPadding(new Insets(0, 4.3, 0, 0));

        titledPane2.setGraphic(lbl1);

        Label lbl12 = new Label(
                "Delhi is a crowded city. There are very few rich people who travel by their own vehicles. The majority of the people cannot afford to hire a taxi or a three-wheeler. They have to depend on D.T.C. buses, which are the cheapest mode of conveyance.");
        lbl12.setWrapText(true);
        lbl12.setPadding(new Insets(4.3));

        titledPane2.setContent(lbl12);

        root.getChildren().addAll(titledPane2);

        Platform.runLater(() -> {
            Pane title = (Pane) titledPane2.lookup(".title");

            title.prefHeightProperty().bind(lbl1.heightProperty()
                    .add(title.getInsets().getTop() + title.getInsets().getBottom()));
        });

        return root;
    }

Output: image

But it's more better if it's fixed in official javafx or jpro-one -> custom javafx.

FlorianKirmaier commented 1 year ago

@ctoabidmaqbool Great to hear you've fixed your problem! We've made a lot of fixes for JavaFX bugs and have been playing with the thought of our own JavaFX Fork for quite some time, mainly because we've got a lot of bugfixes that are not yet in the official JavaFX.

I'm closing the ticket now.