1

Im trying to make a fullscreen application. I would like to know how to make the component that I add on the JFrame to occupy a part of the screen on every resolution.

Design tab mode:

design tab mode

When I run on fullscreen i get this:

fullscreen mode

how can I make this following interface adjust to full screen? enter image description here

freitas
  • 313
  • 6
  • 16
  • Do you want to keep the same relative size to the siize of the window/screen or the same absolute size? – DSquare Jul 18 '14 at 14:13
  • I want to keep the same relative size to the size of the screen I want also to mention that my app will run always on fullscreen – freitas Jul 18 '14 at 14:16
  • Then there's only 2 things to consider: 1) The layout to use 2) If this "title component" can stretch itself to the size you need at any given time (for example, an image can't be resized but a label with a border can). There's a lot of possible ways (essentially a layout choice) to move forward, which one to choose depends on what else there will be on the window. – DSquare Jul 18 '14 at 14:23
  • Well, It will run on a 1024x768 screen resolution. If the image doesn't look good, I can exchange or simply remove it. I'm using SpringLayout, is it the correct one for the purpose? I can show an image of a previous try. I'm trying to organize the code. – freitas Jul 18 '14 at 14:41

1 Answers1

1

Here's an idea of the some of the basic layout managers and which ones respect preferred sizes (meaning if preferred size is respected, as container expands, component will not expand with it, and vice versa)

enter image description here

That being said, you may want to use a BorderLayout, and place your top component at the BorderLayout.PAGE_START. Ad the screen increases, so will the component contained in that layout position. (Note: the example's main container uses a BorderLayout)

As far as the image, if you want to stretch, I'd take a look at StretchIcon from Darryl Burke. This will keep the image to a relative size.

Also a common practice is to nest panels with different layout managers, to get your desired result. You can see an example here by Andrew Thompson

Also see more about layout managers at Visual Guide to Layout Managers

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • Thanks for your suggestion. As I can see in your idea, GridLayout and BorderLayout ajust to the size of the screen? – freitas Jul 18 '14 at 15:46
  • Not really the size of the screen, but to the size of its container. For instance if you have a button in a panel(GridLayout) but the panel is in another panel(FlowLayout), then the button will not stretch because the flowlayout makes the inner panel the smallest size, which keeps the button the same size, if that makes sense – Paul Samsotha Jul 18 '14 at 15:52
  • I've tried to make a interface only by using SpringLayout, because I can move objects inside it easily. I'll update the post with the image of the interface that i created previously, Now I'm organizing my code and i want to make it fullscreen. Can you give me some tips? – freitas Jul 18 '14 at 15:57
  • I mean it really all depends what you want to happen when the frame resizes. You've just introduced a hundred more component to the problem, as far as this post is concerned. If you _all_ the component to somehow spread apart accordingly as the frame resizes, you will need different layout. Honestly, what your asking is a little broad, and you will need a better understanding of all the different layout managers, and nest different panels with different layout managers to get what you need. Using just one layout manager may not get you the desired result. – Paul Samsotha Jul 18 '14 at 16:07
  • It's ok, I've tested here some different layouts, it is going well. Thanks for your attention mate. – freitas Jul 18 '14 at 16:13