Results 1 to 4 of 4
Thread: JFrame resize control
- 08-23-2010, 05:17 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 1
- Rep Power
- 0
JFrame resize control
Hi
I want to have a control over the user resize in a JFrame. For example i want width will always 300 pixel higher than height. I try this code :
This code is not doing resize until the user did some other action, like moving the JFrame. Is any solution to this?Java Code:public class Test extends JFrame { private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private static int con = 300; /** * This is the default constructor */ public Test() { super(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { this.setSize(500, 200); this.setContentPane(getJContentPane()); this.setTitle("Test"); this.addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent e) { resizeControl(); } }); this.setVisible(true); } /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(new BorderLayout()); } return jContentPane; } protected void resizeControl() { int w = this.getWidth(); int h = this.getHeight(); if(w > h+con) { this.setSize(h+300, h); }else { this.setSize(w, w-con); } } }
Thank you in advance
Charalampos Alexopoulos
- 08-23-2010, 06:25 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,421
- Blog Entries
- 7
- Rep Power
- 17
What happens when you override the setBounds( ... ) methods and call the super implementation with (optionally) adjusted values?
kind regards,
Jos
- 08-23-2010, 10:32 PM #3
Your code works fine for me. It does not allow increasing teh size of the JFrame except by dragging the corner (ie increasing width and height simultaneously). When reducing either width or height, the other gets reduced correspondingly.This code is not doing resize until the user did some other action, like moving the JFrame. Is any solution to this?
db
- 08-24-2010, 07:50 AM #4
Member
- Join Date
- Jul 2010
- Posts
- 32
- Rep Power
- 0
Similar Threads
-
to pass a parameter from a jframe children to its jframe mother
By anix in forum NetBeansReplies: 5Last Post: 06-14-2010, 06:10 PM -
how to resize an image
By marodia in forum AWT / SwingReplies: 2Last Post: 08-21-2009, 04:10 AM -
Image Resize
By jithan in forum New To JavaReplies: 4Last Post: 11-07-2008, 09:26 AM -
control app width based on certain control
By thebillybobjr in forum SWT / JFaceReplies: 0Last Post: 05-15-2008, 04:52 PM -
Resize frame
By lenny in forum AWT / SwingReplies: 1Last Post: 07-29-2007, 11:18 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks