Results 1 to 15 of 15
  1. #1
    Y. Progammer is offline Member
    Join Date
    Feb 2010
    Posts
    68
    Rep Power
    0

    Default How to resize the component dynamically??

    consider launch of an application ...




    now when i maximize the application....



    you people can notice the difference ..i want to dynamically change the size of the textarea so that the gap is filled dynamically.. plz suggest:p

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    What Layout manager did you use for this?

    kind regards,

    Jos

  3. #3
    Y. Progammer is offline Member
    Join Date
    Feb 2010
    Posts
    68
    Rep Power
    0

    Default

    no not .. can you suggest one meting the requirment of my problem??:rolleyes:

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Y. Progammer View Post
    no not .. can you suggest one meting the requirment of my problem??:rolleyes:
    No layout manager, no flexible repositioning of the child components; sorry.

    kind regards,

    Jos

  5. #5
    Y. Progammer is offline Member
    Join Date
    Feb 2010
    Posts
    68
    Rep Power
    0

    Default

    isn't there any.. any other way to achieve so?? i mean apart using layout manager.... :(

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Y. Progammer View Post
    isn't there any.. any other way to achieve so?? i mean apart using layout manager.... :(
    Not realy; your code has to be notified when the parent component changes its size and then you have to resize and reposition all your child components. I'd use a layout manager if I were you; start reading here.

    kind regards,

    Jos

  7. #7
    Y. Progammer is offline Member
    Join Date
    Feb 2010
    Posts
    68
    Rep Power
    0

    Default

    I think its a drawback in java!

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Y. Progammer View Post
    I think its a drawback in java!
    No it isn't; there are layout managers that handle it all for you; you don't have to write a line of code (except for installing the layout manager). It's not Java's fault that you don't understand the concepts (I pointed you to the tutorials).

    Think of it: you pinpoint several child components because you want them exactly there; what is the parent component supposed to do when it is resized? Be creative and put them somewhere else without your permission?
    Study those layout managers.

    kind regards,

    Jos

  9. #9
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    Can you suggest one layout manager that can rearrange the components exactly in the same orientation as they are in ... i mean i too tried most of the lay out managers but not found such a flexible one.. border or flow or others:rolleyes:
    The Quieter you become the more you are able to hear !

  10. #10
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Stephen Douglas View Post
    Can you suggest one layout manager that can rearrange the components exactly in the same orientation as they are in ... i mean i too tried most of the lay out managers but not found such a flexible one.. border or flow or others:rolleyes:
    Why doesn't a FlowLayout (LEADING) work in this example? You have to put a few JPanels in there for the JComponents that are stacked vertically; or use a GridBagLayout, but that's a more complicated layout manager.

    kind regards,

    Jos

  11. #11
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    I think its a drawback in java!
    Its a strength. Other languages don't have this feature because they weren't designed to support the concept of dynamically laying out components.

    It's not Java's fault that you don't understand the concepts (I pointed you to the tutorials).
    Exactly.

    Why don't people understand that if you want to position/size components when the frame size changes you need to add a component listener to the frame. Then when the listener fires you recalculate the size and location of each component based on the rules you define. So in effect you are creating a custom layout manager.

    This is exactly what a layout manager does. So why rewrite layout code every time when you can reuse existing layout managers? Me, I'm lazy I like to reuse code rather than rewrite it from scratch every time.

  12. #12
    Stephen Douglas's Avatar
    Stephen Douglas is offline Senior Member
    Join Date
    Mar 2010
    Posts
    137
    Rep Power
    0

    Default

    You have to put a few JPanels in there for the JComponents that are stacked vertically
    I think thats a gr8 idea....

    by the way i designed a pattern that enables the components to be re- oriented whenever the window is resized.. plz feedback.

    The Quieter you become the more you are able to hear !

  13. #13
    Y. Progammer is offline Member
    Join Date
    Feb 2010
    Posts
    68
    Rep Power
    0

    Default

    I think its a drawback in java!
    The drawback i'm talking about is the "resizing of the components" and not the "rearrangments of the components" ........... i think i made it much clear !

  14. #14
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    The drawback i'm talking about is the "resizing of the components" and not the "rearrangments of the components" ........... i think i made it much clear !
    A layout manager provide 2 main functions (there are others):

    a) resizing by invoking setSize()
    b) rearrangement by invoking setLocation

    You can't resize the intial text area without changing the location of the other components as well. That why the job is best left to a layout manager rather that writing your own custom code every time.

  15. #15
    Y. Progammer is offline Member
    Join Date
    Feb 2010
    Posts
    68
    Rep Power
    0

Similar Threads

  1. how to resize an image
    By marodia in forum AWT / Swing
    Replies: 2
    Last Post: 08-21-2009, 04:10 AM
  2. Image Resize
    By jithan in forum New To Java
    Replies: 4
    Last Post: 11-07-2008, 09:26 AM
  3. resize tabs in jtabbedpane
    By osval in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 03:02 AM
  4. Resize frame
    By lenny in forum AWT / Swing
    Replies: 1
    Last Post: 07-29-2007, 11:18 PM
  5. Help with JTextArea, resize windows
    By paul in forum AWT / Swing
    Replies: 1
    Last Post: 07-16-2007, 04:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •