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().
Related
I'm wondering how I can add (what LayoutManager should I use) to make the app automatically adjust the components to the current size when full screen mode is enabled or even when the frame is stretched.
Currently this is what the application looks like, when you enable full screen mode the components are static.
UPDATE: I'm pasting pictures so you can get an idea of what I wrote.
Component layout in IntelliJ: layout
The current design in the small window looks ok: current design
Appearance if we enlarge the window (window zooms in, elements are static): full screen
So I'd like the components to automatically resize to the current window when fullscreen mode is enabled.
Okay. I suggest the following design:
your mainPanel, that you assigned as contentPane for your frame gets a Borderlayout.
In the North, you put a panel with a label or just a label, with Allignment X to the left.
the West gets a panel I suggest we call WestPanel and the East gets another one, which I call EastPanel.
WestPanel gets a Boxlayout or a Gridlayout. If you use Gridlayout, you can use 2 Grids wide and for each line one grid depth. You then can add all the labels in the left column and the textfields on the right.
Or you can make panels, with Borderlayout, labels to the West, textfields to the east, and pile them with emptyBorders ontop of each other. I suggest using a method for that.
The EastPabel gets a Tabbed Pane inside of it. Each tab can have its own layout manager, depending on what you want it to be in the end.
Does this help you?
I want scrollable panes.
Please, have a look at the picture
As you can see at the Navigator, I used Tabbed Pane, then placed Scroll Panes on it. Then placed Panel on it. And then added Lables. Looks like I'm trying to reach my left ear with my right foot. But without the jPanel1 my lable occupied the whole panel size.
Well now my scrollable panel doesn't work well.
It is visible at this .
Well, I made the window narrow. But the scroll bar at the bottom doesn't allow me to reach what is behind the border further on the right. And this scrollbar seems strange. It has only t left arrow. No right one. And no vertical scroll bar if I make the window less high.
Could you give me a hint how to make scrollable windows?
I'm not sure what you're doing wrong this is the results I get when I do only this and nothing more.
Drag and drop a tabbed pane to the frame
Drag and drop a scroll pane to the tabbed pane
Drag and drop a panel to the scroll pane
Drag and drop a label to the panel, and another label to the bottom.
Resize to smaller frame and scroll bars appear
Navigator Window
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 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).
I have a JDialog that consists of two JPanels, one above the other. Currently, when I resize the JDialog only the bottom panel resizes in the vertical direction. However, I only want the top panel to resize. The only component that the top panel contains is a JScrollPane, so I want any vertical resizing to result in an increased/decreased view of the top panel's content. What is a good way to do this?
Thanks in advance!
elise
, I only want the top panel to resize
dialog.add(topPanel, BorderLayout.CENTER);
dialog.add(anotherPanel, BorderLayout.SOUTH);
This is a job for the proper LayoutManger. Here is a good link that explains LayoutManagers visually and does it quite well.