This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes [new user!] I've got an undecorated window, how can I make it resizable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "[new user!] I Watch "[new user!] I New topic
Author

[new user!] I've got an undecorated window, how can I make it resizable?

Breno Salgado
Greenhorn

Joined: Nov 05, 2008
Posts: 11
Hi everyone, Im new to the forum..

in the program Im doing, I've got undecorated and movable windows...but I'd like to know, is there a way to make them resizable?


thanks in advance!


Breno Santos Salgado -> Brasil, Brasilia, DF.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Undecorated but still movable? How did you do that?

Because it's the decoration that usually allows for things such as moving and resizing.

Moving to AWT / Swing since it's clearly user interface related.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Breno Salgado
Greenhorn

Joined: Nov 05, 2008
Posts: 11
Originally posted by Rob Prime:
Undecorated but still movable? How did you do that?

Because it's the decoration that usually allows for things such as moving and resizing.

Moving to AWT / Swing since it's clearly user interface related.


here is how you make movable undecorated window...I wasnt the creator of this code, I just added the if(!e.isMetaDown()) so only the left button would work for moving the window(just like the msn ones)

Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Originally posted by Breno Salgado:


here is how you make movable undecorated window...


Well you could do something similar for resizing. You would have to
(1) examine the click more closely to determine if it should be a move gesture, a resize gesture, or neither
(2) call setSize() [or setBounds()] instead of setLocation() on resize gestures

I don't know your requirements ,but I'd be tempted to just use the window decorations.
[ November 05, 2008: Message edited by: Brian Cole ]

bitguru blog
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Originally posted by Breno Salgado:
here is how you make movable undecorated window...

I should have known you'd have done it that way. I've written a mouse listener class just like that. I just never thought of using it for frames / windows, just other components.

As Brian said, you can do the same for resizing. Based on the location you can set the cursor to "new Cursor(Cursor.W_RESIZE_CURSOR)" or one of the other default cursors, and also how the drag will behave: move for the center, and resizing in the right direction for the borders.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
an easy way is to:
set the frame's default look and feel to true
remove the titlePane
set the rootpane's border to an empty border

now you have an undecorated frame, but when you get to the edges
the cursor will change to a resize cursor and you can drag
the frame wider/taller etc
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Title pane? Can you please explain what that is, and how you can remove it? Because the API mentions no such thing (unless I've missed it).
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Breno Salgado
Greenhorn

Joined: Nov 05, 2008
Posts: 11
that's helpfull! thanks!

but damn, I'd like to learn how to do the resize method... Im trying here but I've been unable to test it properly because when I click the retangle thats the box to resize its still using the move method and its getting really messy

I tried with an IF in a higher state but Im getting syntax problems all the time, Im about to give up

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

I've tried Michael's code but it only works with the (current version of) default metal look&feel. If you switch to the system look&feel it fails horribly. And it may also fail in a new version of Java.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> but damn, I'd like to learn how to do the resize method...

here's one way - but I've only added code to resize by dragging to the right (east),
you'll need to add code for the remainder, as well as the corners
(and you may want to modify when the cursor changes to <-->)



[edit] disable smileys, >) is a smiley
[ November 06, 2008: Message edited by: Michael Dunn ]
Iovcev Elena
Greenhorn

Joined: Dec 09, 2009
Posts: 2
Hi! I have the complete solution for full resize of undecorated JFrame and also moving the window



Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Thanks for sharing this, but please Use Code Tags. You can use the edit button to add them.
Iovcev Elena
Greenhorn

Joined: Dec 09, 2009
Posts: 2
Iovcev Elena wrote:The same code with some changes



 
jQuery in Action, 2nd edition
 
subject: [new user!] I've got an undecorated window, how can I make it resizable?
 
Similar Threads
I lack focus...
JFileChooser (Open File Dialog)
Modifying the window.open() parameters
Frame question
Resizable JPopupMenu