my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes replacing objects in diff sized monitors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "replacing objects in diff sized monitors" Watch "replacing objects in diff sized monitors" New topic
Author

replacing objects in diff sized monitors

Sunil chintu
Greenhorn

Joined: Nov 04, 2008
Posts: 8
Hi friends, I developed a java program for 15 inch monitor... now that s/w has to be run in 21 inch monitor.. I want to generalize the positions of all swing objects... Please give me a suggestion so that it can run on the system with any sized monitor..
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10171
    
    8

Hi Sunil.
Welcome to the ranch. We are happy to have you here

By "swing objects" I take it you mean all the components which have been added to the frame/window.

Usually one uses layout managers to define the relative positions of components in its container (as opposed to using a null layout manager and specifying absolute positions using the setBounds() method).
Have you used layout managers in your application?

If the application looks good on a 15" monitor, I would suggest not to tamper with it for other sizes. Usually one defines the minimum screen requirement and designs the UI accordingly. I am sure you must have seen something like "Best viewed on IE7 with 1024x768" kind of stuff lots of times


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Sunil chintu
Greenhorn

Joined: Nov 04, 2008
Posts: 8
Hi Maneesh, thanks for your suggestion...
I completed the coding part using null layout manager..
So is there any other way for me now?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10171
    
    8

Well you can always generate and maintain a mapping.
e.g for
@ AxB resolution bounds for component1 should be..
@ AxB resolution bounds for component2 should be..
.
.
.
@ CxD resolution bounds for component1 should be..
@ CxD resolution bounds for component2 should be..
.
.
..and so forth.
Then at runtime, you load the required mapping and position your components accordingly. But as you can see this is quite a time consuming and tedious task.

An elegant and highly recommended solution would be to use LayoutManagers.
Like I said previously, decide on the minimum configuration like 1024x768 and use the layout managers.
Of course this means changing most of your GUI building code, but it will be a one time effort.

Just curious. Why did you use the null layout?
[ November 05, 2008: Message edited by: Maneesh Godbole ]
Sunil chintu
Greenhorn

Joined: Nov 04, 2008
Posts: 8
ok once again thanks for your suggestion to use layout managers, but can you
tell me which layout manager is good for designing?
Actually this is the first java GUI I developed... So I was in hurry to do
this.. So to make it fast, I used NULL layout manager.
Hey I have one more doubt... I want to disable close, minimize and maximize option of window... what is the API for that?
And I want my software to run in background... that is, it should
come in right side of taskbar and if I click that, then it should open... what to do for that..
Sorry :roll: I am asking so many doubts to you...
Sunil chintu
Greenhorn

Joined: Nov 04, 2008
Posts: 8
ok once again thanks for your suggestion to use layout managers, but can you
tell me which layout manager is good for designing?
Actually this is the first java GUI I developed... So I was in hurry to do
this.. So to make it fast, I used NULL layout manager.
Hey I have one more doubt... I want to disable close, minimize and maximize option of window... what is the API for that?
And I want my software to run in background... that is, it should
come in right side of taskbar and if I click that, then it should open... what to do for that..
Sorry :roll: I am asking so many doubts to you...
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by Sunil chintu:
Please give me a suggestion so that it can run on the system with any sized monitor..


Actually this is the first java GUI I developed... So I was in hurry to do this.. So to make it fast, I used NULL layout manager.


How does this happen? I mean it's somewhat of non-trivial to figure out
how to use the null layout manager, and it's really no easier than using
an actual layout manager (for typical beginning projects, anyway). So
how come we periodically encounter beginners that have used the null
layout manager asking questions here? Is there a book or something that
suggests it?

Anyway, Sunil, one of the reasons layout managers exist is to handle
running on any sized monitor gracefully. Of course it is possible to
do some arithmetic with the null layout manager and have things work
smoothly, but it would be much easier to simply use actual layout
managers and have them deal with it. It's not difficult once you put
in some basic work to discover how layout managers are supposed to work.


bitguru blog
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
You will find lots about creating GUIs here. Lots and lots! It includes layouts, but some people say you ought to Google for MigLayout as being the best manager.
And if you go through the API for GUIs, probably the Window class, you find methods like setResizable. That's probably what you want.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10171
    
    8

Originally posted by Brian Cole:

How does this happen? I mean it's somewhat of non-trivial to figure out
how to use the null layout manager, and it's really no easier than using
an actual layout manager (for typical beginning projects, anyway). So
how come we periodically encounter beginners that have used the null
layout manager asking questions here? Is there a book or something that
suggests it?


Long time back, I remember trying out some DND GUI Builder (Visual Cafe if I remember correctly) In that version, I could specify the absolute location of a component which obviously got translated to the bounds internally.
So this might be such kind of code.
Sunil chintu
Greenhorn

Joined: Nov 04, 2008
Posts: 8
Thank you Maneesh Godbole, Brian Cole, Campbell Ritchie for your valuable suggestion... I will recode the GUI with layout managers.. If I get any doubt, I will get back to you...

But I asked some more doubts... Please send solutions for that..

I want to disable close, minimize and maximize option of window... what is the API for that?
And I want my software to run in background... that is, it should
come in right side of taskbar and if I click that, then it should open... what to do for that..
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10171
    
    8

... that is, it should
come in right side of taskbar and if I click that, then it should open... what to do for that..


Do you mean the System Tray?
Sunil chintu
Greenhorn

Joined: Nov 04, 2008
Posts: 8
yeah its system tray.....
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10171
    
    8

Originally posted by Sunil chintu:
yeah its system tray.....


So did you check out the link I had provided? Was it helpful?
Sunil chintu
Greenhorn

Joined: Nov 04, 2008
Posts: 8
Yeah its really useful...
but i am not getting how to make my application to get into system tray..
please don't feel bad i am really getting all from you only..... :roll:
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Have you tried the code in the link Maneesh has given you? Then you should know how to create a tray icon.

As for minimizing to the tray, all you need to do is add a WindowListener to your (J)Frame that responds to the iconified event. If that one occurs, add the tray icon (if not added already) and call setVisible(false) on the (J)Frame.

Don't forget to change the frame's (extended) state back when you show it again or it will remain iconified (minimized). And if you want to know which method to use for that, read my previous sentence


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sunil chintu
Greenhorn

Joined: Nov 04, 2008
Posts: 8
yeah i will do that... thanks to all.. especially maneesh
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10171
    
    8

Originally posted by Sunil chintu:
yeah i will do that... thanks to all.. especially maneesh


You are welcome. Hope you get your solution working the way you want it.
Best of luck
 
Consider Paul's rocket mass heater.
 
subject: replacing objects in diff sized monitors
 
Similar Threads
Monitor Size
JToolBar button problem
skin screen size (emulator)
JFrame
JavaScript evaluation code ...