• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Breno Salgado
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Rob Spoor
Sheriff
Pie
Posts: 20671
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Breno Salgado
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 908
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Rob Spoor
Sheriff
Pie
Posts: 20671
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20671
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Breno Salgado
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20671
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! I have the complete solution for full resize of undecorated JFrame and also moving the window



 
Rob Spoor
Sheriff
Pie
Posts: 20671
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for sharing this, but please Use Code Tags. You can use the edit button to add them.
 
Iovcev Elena
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Iovcev Elena wrote:The same code with some changes



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic