Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-24-2007, 04:15 PM
Member
 
Join Date: Jul 2007
Posts: 40
lenny is on a distinguished road
Resize frame
Hi, For a program we have to have a frame, with a JComponent inside it, and then a few objects drawn on it. All of which is no problem but the last thing that is needed, is when the entire frame is resized, all of the pieces inside it need to stretch out as well.
This is where my problem is, I think it is because the paintComponent method needs to be called again when the frame is resized but I do not know how to do that.
All of my drawing statements use variables as opposed to set sizes, so it should all work if I could update it after the frame is resized.
Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-30-2007, 12:18 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,104
hardwired is on a distinguished road
The trick is to base your variable values on the current size of the component.
Code:
import java.awt.*; import javax.swing.*; public class StretchyGraphics extends JPanel { protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); g2.drawRect(w/16, h/16, w*7/8, h*7/8); } public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new StretchyGraphics()); f.setSize(400,400); f.setVisible(true); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
close a frame.. tajinvillage New To Java 5 04-27-2008 11:22 PM
Problems with gridBaglayout when I resize the window Iyengar AWT / Swing 1 02-17-2008 12:43 AM
resize tabs in jtabbedpane osval New To Java 1 08-02-2007 04:02 AM
Help with JTextArea, resize windows paul AWT / Swing 1 07-16-2007 05:11 PM
Frame Query Daniel AWT / Swing 1 07-05-2007 07:27 PM


All times are GMT +3. The time now is 04:21 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org