-1

I am using the NetBeans Designer to create a JFrame. Also it is worth mentioning I am fairly new to Java so I might not understand some things / do things correctly. The frame has about 100 panels, more buttons than I would even think about counting, about ~40 tables, basically most swing components the NetBeans designer provides are being used within the frame. Also for the main frame I am using Null Layout (in order to have a background image inside a JLabel). I know it is not recommended but it doesn't affect the general layout of things as I'm using panels/LayeredPane/TabbedPane for everything, each with it's own design (most of them on Free Design with no Layout specified - that's how I started, didn't know about Layouts and it would take ages now to rearange everything after using Grid Bag Layout for example).

Now getting to my problem, I need to be able to resize the frame and make it resize all components contained. I have to carry a presentation tomorrow of it and I just noticed it doesn't fit on smaller displays (and resizing it doesn't do it properly, it just hides components). I do not care much if it's just an improvisation / not the best approach to the problem as after the 15 min presentation I will probably never open it again. Thanks.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user2399013
  • 75
  • 1
  • 1
  • 6
  • Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or combinations of them, along with layout padding & borders for white space. – Andrew Thompson Jul 09 '13 at 09:04
  • I did not notice *"I have to carry a presentation tomorrow"* 'Kiss your ass good-bye'. I doubt an app. using `null` layout could be converted to one that uses layouts overnight unless you are already comfortable using Java layouts. – Andrew Thompson Jul 09 '13 at 09:09
  • 1
    Buy a bigger display for the presentation ? – Robin Jul 09 '13 at 09:13
  • I am supposed to present it on a 17" Display, I'm not bringing my own. I have designed it on a 23" but the difference - the part that doesn't fit is just about 1". Thanks for help, as I can't properly learn Java Layouts by tomorrow I'm thinking of just arranging in some other way the components of the biggest Panel, the one that doesn't fit, and then just resize it and the whole frame along with it. Flow of the menu/form won't be as good as it is now but if that's the only way I'll do it like that. – user2399013 Jul 09 '13 at 09:20
  • 1
    hope you learned the lesson: **never-ever** do any manual sizing/locating :-) – kleopatra Jul 09 '13 at 09:22
  • ..perhaps putting the entire GUI in a `JScrollPane` would work. It'd look like crap, but might work and be doable 'before tomorrow'. – Andrew Thompson Jul 09 '13 at 09:35
  • 1
    if you are really desparate, you might try JXLayer and TransformUI by Piet Blok (@Mad has a reference to the lost resources, if I remember correctly) - it can scale all the content and keep the controls active – kleopatra Jul 09 '13 at 09:48

1 Answers1

2

I would try to go through all the components tree and try to set them smaller font and reduce all their bounds to some static %.

In other words for each component multiply x,y,widht,height to e.g. 0.75 and call setFont() passing derived font of 25% smaller.

StanislavL
  • 56,971
  • 9
  • 68
  • 98
  • 2
    Seems like a (custom) `CompactPLAF` would be quicker. Especially given *"100 panels, more buttons than I would even think about counting, about ~40 tables"*. But I don't see the OP succeeding at that (creating custom PLAF) overnight either.. – Andrew Thompson Jul 09 '13 at 09:33
  • @AndrewThompson I agree that introducing LAF would be better but it seems this is not option for the user. – StanislavL Jul 09 '13 at 09:52
  • *"it seems this is not option for the user."* What do you base that on? I see nothing in the question that indicates that. – Andrew Thompson Jul 09 '13 at 09:55