This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
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!
 
Sheriff
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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)

 
Author
Posts: 974
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
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
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
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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 ]
 
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
Posts: 21972
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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



 
This tiny ad is suggesting that maybe she should go play in traffic.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic