how to make scrollbar start at the bottom? - java

I'm creating a java chat application using jFrame. I'm using a JScrollPane to scroll the text area. All the new messages are added at the bottom, but the scroll bar starts at the top. How do I make it start at the bottom?

You can force it to scroll to the bottom after adding a message by scrolling its vertical scrollbar directly, e.g.:
JScrollBar vScrollBar = myScrollPane.getVerticalScrollBar();
vScrollBar.setValue(vScrollBar.getMaximum());

Related

JTable scroll bar top right corner

I have a JTable. When scroll bars displayed there is an empty space on the top right as in the screenshot below.
Is there a way to make it like in the following screenshot?

How to exceed the scroll bar beyond the scroll pane in a GUI application

I am designing a online marketing page on GUI(user interface). I have added a scroll pane in my main JFrame. The scroll pane starts from 'vertical position = 20' and so does the scroll bar during run time. I want the scroll bar to start from 'vertical position = 0' instead of 20, with the scroll pane still remaining at 'verticle position = 20'
I've tried changing the maximum and minimum size in the properties, but it doesn't work.
A simple example would help in understanding your issue. In the meantime, try to use the following method in JComponent. This works with the component's viewport ancestor, if it has one, and moves the viewport so the given rectangle area is visible or at least its origin. In your case, you could add the component to view to the scrollPane and then call component.scrollRectToVisible(startRect) to ensure the starting position is correct.
public void scrollRectToVisible(Rectangle rect)

How JTextArea "tells" to JScrollPane to change view position while selecting text by dragging mouse outside visible view?

I have created scroll pane - everything is working fine, but noticed, that if I add JTextArea as view panel, and if I selecting text with mouse by dragging it outside visible view - my scroll pane do not change it's view position to make cursor/selected text visible. I think JTextArea uses some method to notify scroll pane to change view position in such case. How can I notify my custom scroll pane to change position?

gwt scroll pane that takes it size from the other components

I have a screen in gwt where a portion of the screen has a scroll panel. There is a header bar at the top and the rest of the screen is in a scroll panel.
Problem is I can only get the scroll bars to appear if I set the absolute height of the scroll panel. The content in the scroll panel is bigger than the scroll panel but the scroll bars don't appear unless I specify the size of the scroll panel absolutely. The problem with this is it does not take into account the size of the browser window...
Thanks, this answer helped me gwt-layoutpanel-size.
Basically, the bottom line is that if you want the scroll panel to resize and maintain the scroll bars all your parent containers must implement RequiresResize so that the scroll panel can listen for the event and act accordingly.
Your flexibility is severely limited when requiring this behaviour as you can only put the scroll panel inside elements that implement RequiresResize/Provides Resize which are the *LayoutPanels...

stop horizontal scrolling in JTextArea

I want to add a JTextArea to an application. Normally that textarea contains large content and both horizontal and vertical ScrollBars appear when running that application. I want to remove horizontal scrolling; I have found that it is possible with
HORIZONTAL_SCROLLBAR_NEVER field but then it does not show the complete contents (it doesn't wrapped horizontally and move content to next row). how to overcome this. I want to stop horizontal scrolling and put contents in next row without scrolling it on a row.
Try this:
yourJTextArea.setLineWrap(true);
yourJTextArea.setWrapStyleWord(true);
You can change the scroll bar policy:
JScrollPane.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);
This will disable the horizontal scroll bar

Categories

Resources