Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Full screen

 
Nupur Gupta
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a swing application using a JFrame and now realise it should have been in full screen mode. But resizing it now is going to cause all the components to go haywire... is there any way I can use full screen maintaining my current proportions?
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What layout(s) are you using?
 
Nupur Gupta
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nate..thanks for replying.. I am using GridBagLayout...
Maybe I am not doing so correctly...hmmm
 
Maneesh Godbole
Saloon Keeper
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to make a full-screen-mode application resizable? Doesnt make sense. Also it is a bad usability design.

I would recommend the following:
1) Launch in full screen mode (Default)
2) Provide the user with an option of toggling between full screen and non full screen mode.
3) Once the user enters the non full screen mode, s/he can always resize the window.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that applications should resize well whether you plan to use them in full screen mode or in a resizeable frame - then you won't run into problems when you decide to switch between the two - or when users with different screen sizes/resolutions use your application.

GridBagLayout can do this - but make sure you are using use weightx, weighty, and fill - these tell GridBagLayout how to distribute "extra" space in the layout.
 
Nupur Gupta
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not about resizing....I had coded the application to run in a smaller screen....now if I set it to large full screen..everything goes haywire....e.g. I had just two rows..now 2 rows take up the whole screen...and it just looks plain bad.
Thanks so much for your help
 
Maneesh Godbole
Saloon Keeper
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Nathan correctly pointed out, this is the GridBagConstraints issue.
Try this:

//code to initialize GridBagConstraints(gbc) and set various parameters
//Code to add whatever components need to be added

//Now do this
gbc.weightx=1.0;
gbc.weighty=1.0;
gbc.gridy++;
yourContainer.add(new JLabel(" "),gbc);

This will push your components to the top of the container. Whenever the component is resized on the plus side, the extra space will be taken up with the empty JLabel(" ");

Best of luck
 
Nupur Gupta
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks a LOT for your help. However , it is not working.. I don't quite understand. So this is what I have done...

I have a JFrame, to which is added a JPanel(tsPanel). The Grid Layout of tsPanel is set, and I add some components to it. After each component, I add

gbc.weightx=1.0;
gbc.weighty=1.0;
gbc.gridy++;
JLabel test = new JLabel(" ");
gbl.setConstraints(test, gbc);
tsPanel.add(test,gbc);

So next, I open my frame, and I resize it to occupy the full screen(I am not yet using the Java APIs to set full screen mode). I find that my components have gone awry, that is the size and orientation that I had in my un-resized window is not maintained.
Any pointers? Would be much appreciated. Thanks
 
Maneesh Godbole
Saloon Keeper
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at this sample code. Notice my comments inline. Your mistake was that you added the JLabel after every component.

Best of luck

 
Maneesh Godbole
Saloon Keeper
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at this sample code. Notice my comments inline. Your mistake was that you added the JLabel after every component.

Best of luck

 
Nupur Gupta
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much Maneesh! It worked - it is a very big help!!!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic