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.
Related
I have a JTree embedded in a JScrollPane. When the JTree grows bigger than the display can show, the remainder of the tree is located at the bottom outside of the visible range. I expected the JScrollPane to start displaying vertical scrollbars if this happens so that you can scroll the remainder into view. The vertical scrollbars do not appear at all if the JTree is expanded and doesn't fit. Here is how it looks like:
I have both, the horizontal and vertical scrollbarPolicy set to as needed. I also tried embedding the JScrollPane containing the JTree into a JPanel but it didn't help. I'm using the UI designer in IntelliJ IDEA to build the GUI by the way.
Any help on making the vertical scrollbars behave as expected? Forcing them to be shown at all times also doesn't work: They cannot be dragged down regardless.
not use preferredSize.
in UI designer choos JTree element, find property preferredSize and in context menu select Restore default value
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();
I'm trying to make a marquee like effect in my program, the text is determined by the content of a file which will result a dynamic lenght/width for JLabel, and the problems are:
I use drag n drop and GroupLayout since it will auto resize the component, but it doesn't allow me to use setBounds nor the setLocation method.
I tried to change it to null layout, yes I can use the setBounds or the setLocation, and now the problem is that the JLabel cannot auto resize its width to fit the text length.
My marquee text would goes from right to the left screen, and will do the run 2 times.
Any suggestion here? Thanks :)
I have a JTextPane with HTML text.
I used GroupLayout (using WindowBuilder).
I've set the minimum size of my JFrame to 800x600 so the user cannot make it smaller than that.
The app has a big scrolling JPanel the size of the entire window. The top part of the panel is taken up by a JTextPane wrapped in JScrollPane. I have disabled the scroll bars and sized the JScrollPane to make the entire text visible.
In group layout the JScrollPane is set to stay constant vertically, but size horizontally.
My issue is that when the user makes the window larger the JScrollPane also expands, but now there is a big white space left at the bottom of the text pane. Is there a way that I can make JTextPane shrink to fit its contents.
Also if you suggest a different layout, I would be willing to try it.
I used this TextPanePerfectSize example from #camickr to solve a similar problem. The example uses validate() and pack() to adjust to the preferred size. You might be able to adapt it to your situation.
Take a look at SpringLayout. It gives you far more control over the positioning of components. Look at the SpringLayout tutorial if you get stuck.
The trick in your case is to bind the bottom (south) of your JScrollPane to the top (north) of the screen.
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