• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Change the Size Of An Entire GUI

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I built a GUI and after testing it on various platforms I think I would like to make it bigger by a factor of 2.2 or so.

Is there an easy way to just enter the factor 2.2 and have the GUI change by that factor?

I have over 50 components in the GUI. Ideally each one would just enlarge by the factor including the fonts.

This was my first (and only so far) java program. I didn't know anything about layout managers. I used netbeans and it generated all the code.

Anybody have any easy way to go from where I am to where I need to be?

Thanks In Advance,

Pete
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pete Calinski wrote: . . . This was my first (and only so far) java program. I didn't know anything about layout managers. I used netbeans and it generated all the code. . . .

Those are serious confessions You should learn all that sort of thing by yourself before letting NetBeans do it for you.

Chances are, NetBeans will have applied group layout to your GUI so the display will change its size to match the screen. You actually let the user change the size by dragging it with the mouse. Try it on your big screen. You should find the components change size to match.
 
Pete Calinski
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guilty Guilty Guilty.

But I'm "self teaching" myself. First OOP program in my 67 years.

I have called it "like drinking from a firehose".

But I'll stop the whining.

When I expand the window the the controls move but stay the same size.

For example, if I pull the right edge the window gets wider and all the controls move to the right like they are "right justified".

Pete
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When I expand the window the the controls move but stay the same size.



And that is what should happen.

The layout manager may reposition the components based on the rules of the layout manager.

Some components, like a JTextArea should possibly increase in size so more text is displayed, but the font should not change or anything. Think of the way your browser works. The menu and toolbars and text fields and labels all remain the same size, but the area that renders the website changes in size.

If you don't like the way the layout manager moves all the components to the right then you need to use a different layout manager. Read the Swing tutorial on Layout Managers for more information. Also you can always nest panels with different layout manages to get your desired layout.
 
Pete Calinski
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob,

Thank you.

I need to do some homework. I have been through the tutorial but I need to do it a few more times.

I guess I could duck the problem by just going back to the GUI editor and making all the controls larger.

That may be easier and faster then rebuilding with a new layout manager.

Do you know if it would be possible to "encapsulate" what I have in a layout manager that will resize everything or do I have to start from scratch in a new layout manager.
Any guess at a layout manager that would resize everything?

Thanks

Pete
 
Rob Camick
Rancher
Posts: 3324
32
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is nothing that "scales" components (by changing Font size automatically). That is not the job of a layout manager anyway. I have never seen an application that scales the components.
 
Pete Calinski
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I was thinking it might be possible to dynamically resize all the components and text with some code.

It would go through the components sequentially and change the size of each.

Any opinions about if this would be possible or would it be an exercise in frustration?

 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, but you would end up doubling the length of your GUI code.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you should try JavaFX, where fonts (and many other visual properties) can be set via CSS.
 
Pete Calinski
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It isn't just fonts. I want everything to get larger (or smaller) like a Zoom In, Zoom Out of the entire GUI.
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Pete,

well, I guess it is possible, but.....

Here is some code that rescales everything within a frame, when the frame
is resized. That's the good news.



The bad news is that there are some major drawbacks.

For instance: in my progrma the button does not actually change its location or size.
So, when you shrink the frame, and the button, it will not detect mouse clicks correctly.
And make the frame smaller and move the mouse over the button. Anything that you notice?

Then the layout manager doesn't work as I would like it to work. Enlarge the frame,
and you'll see what I mean.

So, although it is a start, you need other things as well. First of all, you need to intercept
all mouse clicks over your frame. Doing this with the glasspane is a possibility.
Then you have you determine what original part that click represents, and determine the
corret component for which the cick was meant. And so on. Not for the fainted of heart.

It is certainly nice to give it a try to see how far you can go.

There are alternatives. Darryl mentions JavaFX. Although I myself just started learning JavaFX,
I think it is the best option.

Other possibilities involve making the size of every component relative to the content pane.
That will involve many revalidates, and that will not be easy and/or fast in any way.
Never tried it though, so who knows.

In 9 days, at Coursera website, a course on Android programming will start, which I will
follow as well. See if that comes with some auto resize possibilities.

And lastly: Campbell said in a positive way, that it is possible, at the cost of doubling the code
size. So, maybe he has already some sample code that he could share.

Greetz,
Piet
 
Pete Calinski
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Piet,

Wow, I have to try this.
But right now I have a Windows 8.0 machine that I "upgraded" to 8.1 and completely screwed up.
I have to get it repaired by Monday morning.
This could be a long weekend.

But I will get to this.

Thanks
Pete
reply
    Bookmark Topic Watch Topic
  • New Topic