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?
Related
I have a FlexTable that houses a ScrollPane, which contains a DataGrid.
THe ScrollPane is set to a 100% width, 450px height. The DataGrid is set to 200% width, and 450px height.
The horizontal scroll bar allows me to scroll the table horizontally as expected. However, the vertical scroll bar that lets me scroll through different rows only is visible if I'm scrolled all the way to the right. Is there a way to change this behavior so that the vertical scroll bar is always visible on the right hand side, like in C#'s DataGrid, for example?
I'm looking at the API for DataGrid and do not see anything useful. I have alwaysShowScrolLBars set to true.
My issue was that I shouldn't put a DataGrid inside a ScrollPane since GWT's DataGrid has scrolling built in. To get the desired scrolling behavior, i set the size of the data grid, and then teh size of the table (which is larger than the overall datagrid widget).
// full width, 55% height
int dataGridPixelHeight = (int) (Window.getClientHeight() * 0.55);
m_resultsDataGrid.setSize("100%", dataGridPixelHeight + "px");
// sets the actual inner grid to be wide, allowing horizontal scroll
m_resultsDataGrid.setTableWidth(200, Unit.PCT);
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());
In my application, I have two swing components on top of each other, that look something like this picture. The problem is that the orange component needs a vertical scrollbar, but I want the right edges of the components to stay exactly aligned (and the width can vary as the user makes the app wider or narrower). If I use something like a grid layout, the scrollbar takes up space and then the scrollbar lines up with the right edge of the red component.
I'm thinking I might need to use a scrollbar component and add that separately and use it to control the orange component. Is there a way to attach a scrollbar to another component like that? I would think it would be difficult without using a scrollpane.
I'm also open to any suggestions on how else to approach this.
It shouldn't be too hard to implement the approach you suggested. Wrap the orange component in a JScrollPane, but configure the scroll pane to hide both scrollbars. Then, set the scroll model for the vertical scroll bar in the scroll pane to the scrolling model from the standalone scrollbar. Even though the scroll pane scroll bar is hidden, it will still scroll if the models are linked. See my answer in this question for some code - it's a different application but similar principle.
Alternatively, you could use a JScrollPane with a visible vertical scrollbar, and add a spacing component next to the red component to keep it aligned. I'm thinking you could use a GridBagLayout with two columns. The first row holds the red component and the spacer, and the second row holds the scroll pane with the orange component, which spans both columns. Then, you just have to get the width of the scroll bar component from the JScrollPane and set the preferred width of the spacer to the same value. A drawback with this strategy would be that it could be difficult to keep the spacer size updated if the scrollbar width changes (due to a UI change, for example).
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...
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