GWT - How to center contents inside ScrollPanel - java

I have a FormPanel inside a ScrollPanel. The ScrollPanel is located in the center part of DockLayoutPanel. I want to vertially and horizontally center the FormPanel inside the ScrollPanel. I tried a few ways to do this but no success.
I have tired putting a verticalPanel/horizontalPanel inside the scroll panel, and use it to wrap the formPanel. I set both scroll panel and horizontal panel to 100% width and height. However, the scroll panel is automatically resized according to the size of center part of DockLayoutPanel whereas the horizontal panel's size is always equals to the size of its child- form panel. So I cannot center the formpanel inside of horizontalPanel since their height and width are the same. I try to make the horizontalPanel's size be always the same as scrollPanel, but I have no idea how to do this. Setting horizontalPanel's size to 100% is not working.
So My question is this:
1.How do you center something in scrollPanel. I don't mind using css method if you know how to achieve this.
2.In my case above, is it possible to make the horizontalPanel to be always the same size as its parent container - scroll panel. If it is possible, my 1st question is solved then.

I had to center an image inside a horizontal scroll-panel. Sometimes I just have one image and sometimes there is a list of images to be centered and shown. I have fixed the size of the GWT image object and the width of the scroll panel.
I computed the scroll position inorder to center all the items and I used set scroll position (position can be -ve or +ve values).
When user scrolls the items then I would respect the user's decision and scroll them accordingly. However, if the user scrolls to extreme right of left, I would ensure that the scrolling positions are re-adjusted to scroll back to the boundary and not exceed it.
When the page is refreshed by scroll panel centres the items automatically.
In short, you need to center the items programmatically and by default the scroll panel would keep the items on one side (left and top).

Related

How to fix a panel of a splitPanel?

I would like to know how to fix the JPanel2(in my imported image) to the right side of the application. I am using a JSplitPane so I can resize my JPanel2 with the splitter. When I resize the window, I want the JPanel2 to keep the same size as I set before and the JPanel1 to stretch. For example:
Does anyone have an idea ? Thx.
From what I understand, you want to adjust the size of the left panel only on window resize. You might also want to anchor the jSplitPanel to the window size.
To anchor the jSplitPanel to the window size, left click on the jSplitPanel, go to Auto Resizing and check Horizontal and Vertical.
To adjust the size of the left panel only, you want to add
jSplitPanel.setResizeWeight(0);
In the window init().

JavaFX: bind to scrollpane width and height without bar sizes

I have a StackPane, which is inside a ScrollPane. I want that minimal size of StackPane was as the size of ScrollPane. This is my code
stackPane.minWidthProperty().bind(scrollPane.widthProperty());
stackPane.minHeightProperty().bind(scrollPane.heightProperty());
However, using this code the scroll bars (vertical and horizontal) are always visible and there is a small scrolling. I suppose that I include scroll bar size in minimal size of StackPane. How can I make StackPane minimal size be equal to ScrollPane and scroll bars are not visible if they are not needed?
Late Answer but maybe someone needs a solution.
All you need to do is to add a small offset like that:
stackPane.minWidthProperty().bind(scrollPane.widthProperty().subtract(20));
stackPane.minHeightProperty().bind(scrollPane.heightProperty().subtract(20));

Java GridLayout how to dynamically change grid layout

I am trying to create a character sheet program that arranges 3 panels based on how wide the frame is. If the frame is not very wide, I want the panels to be arranged vertically, but if the user chooses to make the frame wider, I would like to arrange the panels horizontally.
I also have a scrollPanel that the 3 panels are arranged on, so the scrollPanel is being added to a scrollPane.
I have seen posts that say that an eventlistener would work, however most of these are for buttons, and I need the Frame size to pass a certain threshold before the layout changes. I seen other posts that recommend html which I don't see as necessary right now.
So in this picture the 3 panels are arranged vertically, and are able to be scrolled through.
scrollPanel.add(leftPanel); //this is the yellow panel that is being added
scrollPanel.add(centerPanel); //this one is farther down
scrollPanel.add(rightPanel); //even farther down
scrollPanel.setBackground(Color.CYAN);
scrollPanel.setLayout(new GridLayout(0, 1)); //so here I would like to have an if statement or event swap the 0 and the 1.
Summary:
Can I change a GridLayout dynamically based on the size of a Frame?
How do I monitor for a Frame size change? event? if statement?
Can I do the same with a ScrollPane with setting the horizontal and vertical scroll bars to never appear based on if the panels are vertical or horizontal?
You can change the GridLayout as follows:
gr.setRows(newR);
gr.setColumns(newC);
myFrame.validate();
where gr is the layout you created somewhere and newR/newC are the new numbers of rows/columns.
Or you can say
gr=new GridLayout(newR, newC);
myFrame.setLayout(gr);
Then
if(myFrame.getWidth()>thershold) {
.. do the above
}

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.

Is it possible to place the header row of a JViewport at the bottom?

I'm using a JViewport for viewing some data and I'd like the header row to be placed at the bottom of the JViewport rather than the top.
The viewport never scrolls horizontally so the issue of where the scroll bar would go isn't a problem.
I suspect I'm going to have to make my own JViewport-like class which has the header row at the bottom; but before I go off and write that I thought I'd ask.
You can use a panel with a BorderLayout. Add the table to the scrollpane, then add the scrollpane to the center of the panel. Then get the header and add it to the south. Then get the vertical scrollbar and add it to the east.

Categories