problem with textarea in javafx? - java

I used textarea in javafx 2.0 but i need to add it scrolpane.how can i do that?
Scrolllpane s = new Scrollpane();
s.setnode(textarea);
but when i click on scroll pnane it has doesn't move.
what is problem?

setNode() is the right method to call to set the node that the ScrollPane will scroll over. I've used ScrollPane extensively in my 2.0 app, but I have not tried it on Text Area. Based on the API documentation for TextArea (http://download.oracle.com/javafx/2.0/api/com/javafx/preview/control/TextArea.html) it sounds like it has its own built in scroll bars? I would try setting the width/height of the TextArea, and also set the max width/height, and see if you can trigger scrollbars to appear automatically when the lines in the text area exceed the available space.
If you still want to put it in a ScrollPane, perhaps with some other nodes, you should use a container node such as VBox or something to wrap the TextArea, then set the VBox to be your scroll node on ScrollPane.
Also, bear in mind that TextArea is not a committed control for FX 2.0 yet and is therefore less hardened than the other FX controls.

When we create a text area, scroll bar automatically appears when it goes beyond t

Related

Javafx Scrollpane Constraints when inside another Pane

I'm a bit new to Javafx and have only ever done simple projects with it. I'm currently working on a more complex project and I'm stumbled into an issue with ScrollPanes. I'm struggling to find out how to make the ScrollPane resize in height whenever I resize the application. Here is my structure:
The Pane indicated by the orange arrow works fine, I can add constraints as shown here:
However I do not have the constraint options on the ScrollPane or the AnchorPane inside of the ScrollPane, which results in this upon resizing of the application:
If I remove the parent Pane and just put the ScrollPane in it's place, I can add the constraints, however if I did that I would not be able to properly design the application as I have it now. In short, I'm just curious if there's an alternate method I can use or if I'm just using bad practice, in which case any advice is appreciated.
Pane simply resizes the children to the preferred size and keeps the position. This means no resizing is applied. Also it does not offer any further layout constraints.
You could simply replace the parent pane with a AnchorPane and the anchors become available again.
However a AnchorPane(base) containing that many Panes, probably all with different AnchorPane constraints, indicates that the scene should probably be restructured a bit. E.g. a GridPane, VBox, HBox or a combination of those could help you achieve the desired result in a simpler way.
See Using Built-in Layout Panes for a description of the available layouts and example uses.

JavaFX Timeline control

I want to create a scrollable timeline controller with circles connected to a baseline filled with a number ( size of circle corresponding to containing number) and a trailing icon.
Since I am new to JavaFX i have no idea how to start. In Swing i would e.g. use JPanel and ovverride its onPaint() method to draw the circles, lines and icons...
In JavaFX I thought about using a horizontal ListView with custom ListCell, but i am not sure if the baseline is possible with it. So i am looking for ideas how to implementiert such a controll...
Try using a HBox wrapped inside a ScrollPane.
You can add elements to HBox using getChildren.add(node). The elements will be automatically shown on the scene and the ScrollPane will adjust the ScrollBar for you.

Adding Libgdx Scrollbar to TextArea

So I've been searching around and for the life of my cannot figure out how to correctly do this. I simply have a small text area and want to be able to scroll through it. I've been told it's as easy as adding the TextArea to a ScrollPane, but it appears to be more complicated than that. Here's the gist of my code:
Skin defaultSkin = newSkin(DEFAULT_SKIN_FILEPATH +"uiskin.atlas", DEFAULT_SKIN_FILEPATH
+"uiskin.json");
TextArea textArea = new TextArea(levelLoader.getCodeSnippet(), defaultSkin);
ScrollPane pane = new ScrollPane(textArea, defaultSkin);
pane.setForceScroll(false, true);
pane.setFlickScroll(false);
pane.setOverscroll(false, true);
pane.setBounds(0f, 20f, game.getWindowWidth(), 300f);
gui.addActor(pane);
Gdx.input.setInputProcessor(gui);
setIsCreated(true);
levelLoader.getCodeSnippet() returns a string containing a multi-line piece of text from a .txt. The TextArea appears in the game window, and the multi-lined text also appears. However, I can only scroll through the text with the arrow keys. I forced the scrollbar to display itself, but it occupies the entire right side of the window like this:
http://s27.postimg.org/vqws36k77/pic.png
It will not scroll and thinks there are not multiple lines to scroll through even though there are evident by scrolling through with the arrow keys. I've also tried making the textArea larger than the scrollPane, but might have done it incorrectly. What am I doing wrong here?
Update: I've tried both placing the ScrollPane inside of a table and setting the cell size of the table. Any other suggestions would be appreciated.
This is not best solution. I guess it is LIBGDX update layout bug.
This is workaround solution that works for me:
Set pref. rows manually and update scroll layout, when the number of the rows is changed.
textArea.setPrefRows(numberOfScrollLines);
//numberOfScrollLines = text.split("\n").length
pane.layout();

need noRepaint() when i validate()

I have a JScrollPane with a View. I'm doing a chat application , it's why i need to have my ScrollBar to the Maximum(). To get the right Maximum of the View i have to validate before. When I validate my ScrollPane an automatic repaint is doing. I don't want this repaint because it makes a double repaint when i set the ScrollBar to the Maximum : when the ScrollBar is at the top and a another when it is a the bottom.
my code :
Main.getWindow().getMainPanel().getScrollPaneCenter().validate();
scrollPaneCenter.getVerticalScrollBar().setValue(scrollPaneCenter.getVerticalScrollBar().getMaximum());
PS : I want to disable the repaint of my conponent or maybe you have a solution to have a reversed JScrollPane( to always have the ScrollBar to Bottom) .
I'm doing a chat application
I'm guessing your are using a a JTextArea or JTextPane.
it's why i need to have my ScrollBar to the Maximum().
You don't need to validate or set the scrollbar manually. You juat append the text to the bottom of the Document. See Text Area Scrolling for a couple of solutions.

How does a scroll pane do scrolling

In windows, Java, etc, the scroll pane scrolls the widgets inside. What I'm wondering is, how exactly does it do its scrolling? Does it change the location of each nested widget, or does it have a content widget that it moves around? Or is it something else? Also, when both scrollbars are present, how does it mask that little square at the bottom right? That square is sometimes used to resize. Is it a separate nested widget?
Thanks
I think it just changes the location of the widget, button, or thing-a-ma-bober.
But my second guess would be it just draws the components "outside" of the scroll pane without being seen and when you scroll it just redraws dynamically.

Categories