Resizing Components of JPanel in Beans

Discussion in 'Java' started by asd, Mar 4, 2007.

  1. asd

    asd Guest

    Hello All,

    I am developing a bean. I am using JPanel and in that JPanel there is a
    list box.

    After user drags and drops the bean to BDK everything works perfect. After
    the user resizes the bean (JPanel) only the beans gets resized and its
    contents still have the same small size.

    Is there a way to resize the components of a JPanel when doing beans?

    In addition to that, which function of the bean (JPanel) is called when it
    is being resized? I tried overriding several functions (setSize,
    resize etc) but they are not called when the bean is resized in BDK.
    Thank you so much for your help.
    Sincerely yours.
     
    asd, Mar 4, 2007
    #1
    1. Advertising

  2. On Mar 5, 7:04 am, asd <> wrote:
    > Hello All,
    >
    > I am developing a bean. I am using JPanel and in that JPanel there is a
    > list box.
    >
    > After user drags and drops the bean to BDK everything works perfect. After
    > the user resizes the bean (JPanel) only the beans gets resized and its
    > contents still have the same small size.


    It sounds as though you may need to become
    familiar with layouts, are you familiar with
    the term?

    > Is there a way to resize the components of a JPanel when doing beans?


    Sure, if the code is done right, the user
    drags the window bigger/smaller, and the
    component automatically adjusts.

    There should be no need, generally, for the
    developer to set the size of basically anything
    beyond custom compontents, and maybe JScrollPane's.

    If you need to set a size, it usually indicates
    a problem with the layout(s).

    Andrew T.
     
    Andrew Thompson, Mar 6, 2007
    #2
    1. Advertising

  3. asd

    asd Guest

    On Mon, 05 Mar 2007 16:42:18 -0800, Andrew Thompson wrote:

    > On Mar 5, 7:04 am, asd <> wrote:
    >> Hello All,
    >>
    >> I am developing a bean. I am using JPanel and in that JPanel there is a
    >> list box.
    >>
    >> After user drags and drops the bean to BDK everything works perfect. After
    >> the user resizes the bean (JPanel) only the beans gets resized and its
    >> contents still have the same small size.

    >
    > It sounds as though you may need to become
    > familiar with layouts, are you familiar with
    > the term?
    >
    >> Is there a way to resize the components of a JPanel when doing beans?

    >
    > Sure, if the code is done right, the user
    > drags the window bigger/smaller, and the
    > component automatically adjusts.
    >
    > There should be no need, generally, for the
    > developer to set the size of basically anything
    > beyond custom compontents, and maybe JScrollPane's.
    >
    > If you need to set a size, it usually indicates
    > a problem with the layout(s).
    >
    > Andrew T.


    Hello Andrew,

    Thank you so much for your time.
    I have a JScrollPane and a JList in a JPanel. Using the default layout
    manager nothing happens. The size of the JScrollPane
    does not change. Now I removed the layout manager. I manually adjust the
    size of the JScrollPane when ever the user clicks on it.

    I would be glad if you could mention me how to do it using the layout
    manager. An example code will be perfect if you have time and will to
    send one.
    Thanks again.
    Sincerely yours.
     
    asd, Mar 6, 2007
    #3
  4. asd

    Ian Wilson Guest

    asd wrote:
    > I have a JScrollPane and a JList in a JPanel. Using the default layout
    > manager nothing happens. The size of the JScrollPane
    > does not change.


    You must be using the layout manager incorrectly, why not post a small
    working Java program that illustrates your problem, then people can
    point out how to fix it.


    > Now I removed the layout manager. I manually adjust the
    > size of the JScrollPane when ever the user clicks on it.


    Removing the layout manager seems rather foolish to me.


    > I would be glad if you could mention me how to do it using the layout
    > manager. An example code will be perfect if you have time and will to
    > send one.


    I'd use BorderLayout (the default for content panes) and
    add (scroller, BorderLayout.CENTER);
    http://java.sun.com/docs/books/tutorial/uiswing/layout/border.html
     
    Ian Wilson, Mar 6, 2007
    #4
  5. asd

    asd Guest

    On Tue, 06 Mar 2007 09:27:01 +0000, Ian Wilson wrote:

    > asd wrote:
    >> I have a JScrollPane and a JList in a JPanel. Using the default layout
    >> manager nothing happens. The size of the JScrollPane
    >> does not change.

    >
    > You must be using the layout manager incorrectly, why not post a small
    > working Java program that illustrates your problem, then people can
    > point out how to fix it.
    >
    >
    >> Now I removed the layout manager. I manually adjust the
    >> size of the JScrollPane when ever the user clicks on it.

    >
    > Removing the layout manager seems rather foolish to me.
    >
    >
    >> I would be glad if you could mention me how to do it using the layout
    >> manager. An example code will be perfect if you have time and will to
    >> send one.

    >
    > I'd use BorderLayout (the default for content panes) and
    > add (scroller, BorderLayout.CENTER);
    > http://java.sun.com/docs/books/tutorial/uiswing/layout/border.html


    I compiled following code as a Bean. When the size of the panel Changes
    the size of the JScrollPane stays the same. I would like size of
    ScrollPane to always fit the size of the Panel.
    I hope I made myself clear this time.




    public class TestFoolness extends JPanel{
    JList lst;
    JScrollPane pn;

    /** Creates a new instance of TestFoolness */
    public TestFoolness() {
    super(); // gets default layout manager

    lst = new JList(new String[] {"asd", "qvy", "zxc"});
    pn = new JScrollPane(lst);

    add(pn);

    }

    }
     
    asd, Mar 7, 2007
    #5
  6. asd

    asd Guest

    On Tue, 06 Mar 2007 17:28:16 -0800, asd wrote:

    > On Tue, 06 Mar 2007 09:27:01 +0000, Ian Wilson wrote:
    >
    >> asd wrote:
    >>> I have a JScrollPane and a JList in a JPanel. Using the default layout
    >>> manager nothing happens. The size of the JScrollPane
    >>> does not change.

    >>
    >> You must be using the layout manager incorrectly, why not post a small
    >> working Java program that illustrates your problem, then people can
    >> point out how to fix it.
    >>
    >>
    >>> Now I removed the layout manager. I manually adjust the
    >>> size of the JScrollPane when ever the user clicks on it.

    >>
    >> Removing the layout manager seems rather foolish to me.
    >>
    >>
    >>> I would be glad if you could mention me how to do it using the layout
    >>> manager. An example code will be perfect if you have time and will to
    >>> send one.

    >>
    >> I'd use BorderLayout (the default for content panes) and
    >> add (scroller, BorderLayout.CENTER);
    >> http://java.sun.com/docs/books/tutorial/uiswing/layout/border.html

    >
    > I compiled following code as a Bean. When the size of the panel Changes
    > the size of the JScrollPane stays the same. I would like size of
    > ScrollPane to always fit the size of the Panel.
    > I hope I made myself clear this time.
    >
    >
    >
    >
    > public class TestFoolness extends JPanel{
    > JList lst;
    > JScrollPane pn;
    >
    > /** Creates a new instance of TestFoolness */
    > public TestFoolness() {
    > super(); // gets default layout manager
    >
    > lst = new JList(new String[] {"asd", "qvy", "zxc"});
    > pn = new JScrollPane(lst);
    >
    > add(pn);
    >
    > }
    >
    > }


    Thank you so much for your help Ian. After trying several different
    things. I figured that out it works with BorderLayout. I had been trying
    to do it with default LayoutManager.
    I really appreciate your help.
     
    asd, Mar 7, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. steve smith
    Replies:
    0
    Views:
    558
    steve smith
    Jul 10, 2003
  2. Andreas Beresko

    Add a JPanel to a JPanel...

    Andreas Beresko, Jul 14, 2004, in forum: Java
    Replies:
    6
    Views:
    27,154
  3. Torsten Schmeissel
    Replies:
    0
    Views:
    440
    Torsten Schmeissel
    Apr 29, 2005
  4. Raphael Jolivet

    [JPanel] Drop Down JPanel

    Raphael Jolivet, Jul 18, 2008, in forum: Java
    Replies:
    1
    Views:
    1,624
    John B. Matthews
    Jul 18, 2008
  5. t1m1976
    Replies:
    1
    Views:
    2,519
    t1m1976
    Nov 7, 2010
Loading...

Share This Page