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

Caret Position = InlineCssTextArea .getText().length() but it doesn't scroll vertically to the bottom #433

Closed
goxr3plus opened this issue Jan 21, 2017 · 16 comments

Comments

@goxr3plus
Copy link
Collaborator

goxr3plus commented Jan 21, 2017

  • Java Version: jdk1.8.0_112

  • RichTextFX Version: richtextfx-fat-0.6.10.jar

I am using :

InlineCssTextArea textArea = new InlineCssTextArea();
textArea.setEditable(false);
textArea.setFocusTraversable(false);

and i am trying to scroll programmatically at the bottom :

//It returns the maximum length of the InlineCssTextArea  `text`
System.out.println(textArea.getText().length());
System.out.println(textArea.getCaretPosition());
   		    
//It doesn't scroll to the end
textArea.positionCaret(textArea.getText().length());

The problem is that the length of InlineCssTextArea text is 830 even if the caret is positioned at 830 it doesn't scroll to the bottom...

screenshot49984

Is it a bug?

@JordanMartinez
Copy link
Contributor

Are you using positionCaret intentionally? The right way to move the caret is via moveTo (I don't know if that will fix your problem).

@goxr3plus
Copy link
Collaborator Author

goxr3plus commented Jan 22, 2017

Hello Jordan Martinez , thanks for fast reply .

I have tried your recommendation with different ways but again that Vertical scroll bar position doesn't seem to move down . Is there any other solution?

Best Regards.

@JordanMartinez
Copy link
Contributor

@goxr3plus Can you provide a simple Application that reproduces the bug? I could probably help troubleshoot what's going on later on today as I'm not as familiar with the 0.6.10 release since it was released so long ago.

@goxr3plus
Copy link
Collaborator Author

goxr3plus commented Jan 25, 2017

@JordanMartinez

Below is a simple working example showing the problem . I had run it on Window 10:

I will be very glad to download the newer version of RichTextFX but the links seem to be dead ( https://github.com/TomasMikula/RichTextFX/releases/download/0.7-M3/richtextfx-0.7-M3.jar ) , or those who working are giving as option the version 0.6.10 . The link for the newer repositories will be gold :) .

import java.util.Arrays;

import org.fxmisc.richtext.InlineCssTextArea;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;

/**
 * @author Alexander
 *
 */
public class Tester extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {

	primaryStage.setTitle("Testing InlineCssTextArea Vertical ScrollBar");

	// --------------------------------------------------
	InlineCssTextArea textArea = new InlineCssTextArea();
	textArea.setEditable(false);
	textArea.setFocusTraversable(false);
	textArea.setMinSize(500, 200);
	// textArea.setWrapText(true)

	// -------root
	GridPane root = new GridPane();
	root.add(textArea, 0, 0);

	// Append some text to the textArea
	for (int i = 0; i < 200; i++)
	    textArea.appendText("I is : " + i + "\n");

	// Below I am trying to move the Vertical ScrollBar to the Bottom

	// Here it seems to be some kind of bug :) ?
	textArea.moveTo(textArea.getText().length());
	// or
	textArea.positionCaret(textArea.getText().length());

	// -------------------------------------------------

	// Scene
	Scene scene = new Scene(root, 500, 200);
	primaryStage.setScene(scene);

	primaryStage.show();

    }

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

}

@JordanMartinez
Copy link
Contributor

@JordanMartinez
Copy link
Contributor

Or was the deadlink on the ReadMe ?

@JordanMartinez
Copy link
Contributor

I'm pretty sure your code should work, so I'm not sure what's causing the bug. I can reproduce it on my end on Linux.

@JordanMartinez
Copy link
Contributor

JordanMartinez commented Jan 25, 2017

In the 0.7-M3 release, you'll use the code:

area.moveTo(area.getLength());
area.requestFollowCaret();

@goxr3plus
Copy link
Collaborator Author

goxr3plus commented Jan 26, 2017

Thanks for quick reply , i have updated to 0.7-M3 release and created the Tester class a little bit modified as you recommended. The problem got from 1 to 2:

1)No scroll bars by default on the InlineCSSTextArea (Tried to solve with ScrollPane but it doesn't synchronize with the InlineCSSTextArea scrolling)

2)Using:

area.moveTo(area.getLength());
area.requestFollowCaret();

moves the caret to the correct position but the scroll pane isn't even scrolling....

Extra 😃 :
The setStyle(from,to,style) was working with 0.6.10 but now is selecting all the text from InlineCSSTextArea (maybe the specification of the method changed?)


The code (with all different tries):

import org.fxmisc.richtext.InlineCssTextArea;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;

/**
 * @author Alexander
 *
 */
public class Tester extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {

	primaryStage.setTitle("Testing InlineCssTextArea Vertical ScrollBar");

	// --------------------------------------------------
	InlineCssTextArea textArea = new InlineCssTextArea();
	textArea.setEditable(false);
	textArea.setFocusTraversable(false);
	textArea.setMinSize(500, 200);
	// textArea.setWrapText(true)

	textArea.setMaxWidth(Double.MAX_VALUE);
	textArea.setMaxHeight(Double.MAX_VALUE);
	GridPane.setVgrow(textArea, Priority.ALWAYS);
	GridPane.setHgrow(textArea, Priority.ALWAYS);

	// -------root
	GridPane root = new GridPane();
	root.setMaxWidth(Double.MAX_VALUE);
	root.setMaxHeight(Double.MAX_VALUE);
	root.add(textArea, 0, 0);

	// Append some text to the textArea
	for (int i = 0; i < 200; i++)
	    textArea.appendText("I is [" + i
		    + "] some text some text some text some textsome text some text text some text text some text text some text text some text text some text text some text\n");

	// Below I am trying to move the Vertical ScrollBar to the Bottom
	textArea.moveTo(textArea.getLength());
	textArea.requestFollowCaret();

	// -------------------------------------------------

	// Scene
	Scene scene = new Scene(root, 500, 200);

	// Although it shows a scroll Pane it is not synchronized with textArea
	// for example scrolling down on the text area doesn't appear on the
	// ScrollPane

	// Scene scene = new Scene(new ScrollPane(root), 500, 200);

	// or

	// Scene scene = new Scene(new ScrollPane(textArea), 500, 200);

	// Show Stage
	primaryStage.setScene(scene);

	primaryStage.show();

    }

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

}

@JordanMartinez
Copy link
Contributor

1)No scroll bars by default on the InlineCSSTextArea (Tried to solve with ScrollPanebut it doesn't synchronize with the InlineCSSTextAreascrolling)

Ah! Sorry! We decoupled the scroll pane from the area in one of the releases before that one. Now you need to wrap it in a VirtualizedScrollPane:

InlineCssTextArea area = // creation code;
VirtualizedScrollPane<InlineCssTextArea> vsPane = new VirtualizedScrollPane<>(area);

GridPane root = new GridPane();
root.add(vsPane, 0, 0);

@JordanMartinez
Copy link
Contributor

Try this code. I noticed that when wrapText is false, the virtualflow will scroll to the second-to-last line. I'm not entirely sure why that occurs, but it might be due to that line having no content on it. Regardless, when wrapText is true, it works as expected. (I also made the area editable and request focus after the stage is shown, so one can see the position of the caret).

import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.InlineCssTextArea;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;

/**
 * @author Alexander
 *
 */
public class Tester extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {

        primaryStage.setTitle("Testing InlineCssTextArea Vertical ScrollBar");

        // --------------------------------------------------
        InlineCssTextArea textArea = new InlineCssTextArea();
//        textArea.setEditable(false);
        textArea.setFocusTraversable(false);
        textArea.setMinSize(500, 200);
//        textArea.setWrapText(true);

        VirtualizedScrollPane<InlineCssTextArea> vsPane = new VirtualizedScrollPane<>(textArea);

        vsPane.setMaxWidth(Double.MAX_VALUE);
        vsPane.setMaxHeight(Double.MAX_VALUE);
        GridPane.setVgrow(vsPane, Priority.ALWAYS);
        GridPane.setHgrow(vsPane, Priority.ALWAYS);

        // -------root
        GridPane root = new GridPane();
        root.setMaxWidth(Double.MAX_VALUE);
        root.setMaxHeight(Double.MAX_VALUE);
        root.add(vsPane, 0, 0);

        // Append some text to the textArea
        for (int i = 0; i < 200; i++)
            textArea.appendText("I is [" + i
                    + "] some text some text some text some textsome text some text text some text text some text text some text text some text text some text text some text\n");

        // Below I am trying to move the Vertical ScrollBar to the Bottom
        textArea.moveTo(textArea.getLength());
        textArea.requestFollowCaret();

        // -------------------------------------------------

        // Scene
        Scene scene = new Scene(root, 500, 200);

        // Show Stage
        primaryStage.setScene(scene);
        primaryStage.show();

        // focus area so can see the caret
        textArea.requestFocus();
    }

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

}

@JordanMartinez
Copy link
Contributor

Also, I exposed more API in #418 that can accomplish what you desire with show-related methods. For example:

InlineCssTextArea area = // creation code;
area.showParagraphAtBottom(area.getParagraphs().size() - 1);

However, we haven't made a new release with that code yet.

@goxr3plus
Copy link
Collaborator Author

Well done , thank you very much!! I also fixed the problem with the inline styles not working :) 👍

@goxr3plus
Copy link
Collaborator Author

So the issue is maybe done .... :)

@JordanMartinez
Copy link
Contributor

@goxr3plus What's your issue now?

@goxr3plus
Copy link
Collaborator Author

goxr3plus commented Jan 27, 2017

Eveything is working perfect no issues :) . Thanks for help.

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

No branches or pull requests

2 participants