Show the last text on scrollview - java

I'm creating a calculator app. I want the scroll view to scroll as I add new elements (numbers and signs) but it doesn't scroll. Once the text reaches the end of the screen I'm unable to see new elements until I manually scroll.
Then
The remaining part of the text

Try to call scrollView.fullScroll(View.FOCUS_RIGHT) after every text update.

Related

Android Horizontal Layout with text wrap functionality

I want to create an layout, in which I should be able to add views dynamically and it should expand horizontally in a flow.
Here are things that I've tried:
Flow-Layouts
Problem with flow-layouts is that when using multiple textviews, if textview having long text, it takes whole textview to next line, but I want it to wrap the text and only move rest of the text to new line.
Spannable Textviews
I want to assign individual id's to views because when it's clicked it should highlight and function accordingly but with spanning it's not possible.

.How can I spread my text over multiple jtextpanes?

I´m building a simple word-editor in java. Currently, everything´s working fine. Now I want to create "Pages", like in word. The JTextPane representing a Page is supposed to check if it´s full and then create a new JTextpane under it. With a scrollbar I would be able to scroll between them. So far this wouldn't be problematic. However, all the pages should belong to a single document, and if I were to delete a line on let´s say page 2, every line on every other page will be moved up. (For example) Is there an easy way to do this, or will I have to create DocumentListeners for each JTextPane, changing everything on each change? Also, is there a way to extend selections over multiple pages?
Personally I havn't tried anything as of yet, since I want some tips before writing myself into a corner. I thought that I could make the pages uneditable, and instead use a caretListener to check the position the user clicks on, to edit an invisible infinite JTextPane containing the actual document, which would write it´s content to the visible pages.
Lots of unknowns, but maybe the following will give you something to think about.
all the pages should belong to a single document,
Agreed.
The JTextPane representing a Page is supposed to check if it´s full and then create a new JTextpane under it
Maybe add each text pane to a JScrollPane, but don't display the scrollbars or Border of the scroll pane.
if I were to delete a line on let´s say page 2, every line on every other page will be moved up
You would need to manually control the viewport of each scroll pane. The first page would position the viewport at offset 0. The next page would position the viewport at the offset that represents your page height.
Then any changes to the Document should be automatically reflected in all the text panes.
You would also probably need to use setAutoScrolls(false) to prevent the viewport from scrolling as you drag the mouse.
is there a way to extend selections over multiple pages?
Selection is a property of the text pane, not the Document.
Not sure what will happen as you try to drag the mouse from one text pane to another.
I'm guessing you might need some special logic. Maybe using mouseEntered/Exited events to trigger this type of processing.

Move to specific position in TextFlow JavaFX

I'm having a TextFlow inside a StackPane which is inside a ScrollPane. I'm adding text with different colors to this TextFlow
Text txt = new Text(msg);
txt.setFill(Paint.valueOf(color));
txtFlow.getChildren().add(txt);
I want to scroll to a some specific point in the textflow.
e.g. First text that is in blue color.
I know I can get the text and check the color. But how can I scroll down to that specific position?
Can I achieve that sort of functionality through the TextFlow?
Simply I'm trying to build up a diff view in JavaFX. And want to travel through the diffs.
I would take a ListView and put some stackpanes or directly the texts in it.
Text content = new Text("Custom Text");
content.setFill(Color.valueOf(yourcolor));
ListView<Text> list = new ListView<Text>();
list.add(content);
Because...
there's a void scrollTo() where you can scroll to the item directly by the Text object or to the item by the index (int).
To get a transparent background on the listview you can use:
list.setStyle("-fx-background-color: transparent;");
I hope this helped you.
I'm sorry if I missunderstood your question.
Peace
Use one of the free styledtext-editors - they all are using ListView or VirtualView internally. See https://github.com/TomasMikula/RichTextFX/wiki/JavaFX-Controls-for-Code-Editing for examples

ExpandableListViewGroupPosition?

I have implemented ExpandedListView. I have 2 questions for that
When I expand and scroll child item ,the group header also scroll ,is any way to keep that group header at top always even we scrolling child item list ?
Is any way to fit ExpandableListView (before child items comes) to phone screen , right now in bottom lot of blank space ?
For your first question:
no there is no why that you can fix the group view, if you want to fix group i would suggest you to make four list view on screen. where in a Linearlayout make 4 textview and 4 listview placed alternately so that they are fixed and if there is no child inside you can write some appropriate message saying there is nothing to display.
And i guess it solve your second question as well ?
1. When I expand and scroll child item ,the group header also scroll ,is any way to keep that group header at top always even we scrolling child item list ?
No, ExpandableListView's Header's (Parent) and Childs are connected to eachother You can not independently scroll the Child views besides scrolling parent views.
2. Is any way to fit ExpandableListView (before child items comes) to phone screen , right now in bottom lot of blank space ?
You can fit the ExpandableListView by setting its height and width to fixed but it will be always affected as and when you will add some data into it. Till then you can not fit it into the screen.

Scroll text area to top after it has been filled

I have a few text areas that are filled with loops of information. Is it possible to make it 'jump' or scroll back to the top automatically after the loop has completed, so that the user sees it from the start and not the end?
You can use setCaretPosition() to set the cursor at position 0 of the TextArea. That usually works for me.
Use setUpdatePolicy with NEVER_UPDATE, and make sure the setUpdatePolicy comes before setting any text to the JTextArea. In my example I initialize a JTextArea without any text and call setUpdatePolicy right after.
JTextArea jTextArea = new JTextArea();
((DefaultCaret)jTextArea.getCaret()).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
I have solved this problem by creating a new TextArea which acts as a sort of buffer (and isn't displayed). The loop writes to this area and when completed gets the text from that and sets it to the required TextArea.

Categories

Resources