Results 1 to 7 of 7
  1. #1
    Vin
    Vin is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default How to expand the JPanels dynamically?...

    HI,
    I am trying to insert 2 panels within a frame, during run time if I enlarge the frame the panels remains of the same size
    So please can any one tell me how can i enlarge panels too....

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

    Default

    Quote Originally Posted by Vin View Post
    HI,
    I am trying to insert 2 panels within a frame, during run time if I enlarge the frame the panels remains of the same size
    So please can any one tell me how can i enlarge panels too....
    You should've used a LayoutManager on the frame; that manager woud've taken care of that.

    kind regards,

    Jos

  3. #3
    Vin
    Vin is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    hi Jos,
    With which Layout manager i can resize the panels within frame, I tried with GroupLayout manager.

  4. #4
    Vin
    Vin is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    Hi, am tried with this code but i coudn't expand the panels.
    So please help me in solving this probelm..

    public class ExtendPanel extends JFrame {

    private static final long serialVersionUID = 1L;
    private JPanel jPanel0;
    private JPanel jPanel1;
    private static final String PREFERRED_LOOK_AND_FEEL = "javax.swing.plaf.metal.MetalLookAndFeel";

    public ExtendPanel() {
    initComponents();
    }

    private void initComponents() {
    setTitle("ExtendPanel");
    setLayout(new GroupLayout());
    add(getJPanel0(), new Constraints(new Leading(0, 181, 6, 6), new Leading(40, 198, 10, 10)));
    add(getJPanel1(), new Constraints(new Leading(183, 134, 10, 10), new Leading(40, 198, 6, 6)));
    setSize(320, 240);
    }

    private JPanel getJPanel1() {
    if (jPanel1 == null) {
    jPanel1 = new JPanel();
    jPanel1.setBackground(new Color(64, 128, 128));
    jPanel1.setLayout(new GroupLayout());
    }
    return jPanel1;
    }

    private JPanel getJPanel0() {
    if (jPanel0 == null) {
    jPanel0 = new JPanel();
    jPanel0.setBackground(Color.lightGray);
    jPanel0.setLayout(new GroupLayout());
    }
    return jPanel0;
    }

    private static void installLnF() {
    try {
    String lnfClassname = PREFERRED_LOOK_AND_FEEL;
    if (lnfClassname == null)
    lnfClassname = UIManager.getCrossPlatformLookAndFeelClassName();
    UIManager.setLookAndFeel(lnfClassname);
    } catch (Exception e) {
    System.err.println("Cannot install " + PREFERRED_LOOK_AND_FEEL
    + " on this platform:" + e.getMessage());
    }
    }

    public static void main(String[] args) {
    installLnF();
    SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
    ExtendPanel frame = new ExtendPanel();
    frame.setDefaultCloseOperation(ExtendPanel.EXIT_ON _CLOSE);
    frame.setTitle("ExtendPanel");
    frame.getContentPane().setPreferredSize(frame.getS ize());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    }
    });
    }

    }

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Vin View Post
    hi Jos,
    With which Layout manager i can resize the panels within frame, I tried with GroupLayout manager.
    Then you haven't yet read the Sun layout tutorial which I strongly recommend that you do. Laying Out Components

  6. #6
    Vin
    Vin is offline Member
    Join Date
    Jan 2010
    Posts
    8
    Rep Power
    0

    Default

    Hi Jos,
    I have gone through Laying Out Components, with this I have learned laying out components.
    Now can u tell me how to set the layouts so that I can expand the panels in run time on a frame?..

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    You clearly haven't understood the layout tutorial, or you'd know how to set up differet layout managers for a particular panel. Are you coding by hand? It looks like you're using a GUI designer to me.

    (Ooh, look..spam)

Similar Threads

  1. JList and JPanels
    By JetsYanks in forum New To Java
    Replies: 8
    Last Post: 12-25-2009, 03:11 PM
  2. Posistioning Jpanels
    By owain1221 in forum Java Applets
    Replies: 7
    Last Post: 11-16-2009, 12:21 AM
  3. HELP with jPanels
    By maverik_vz in forum AWT / Swing
    Replies: 1
    Last Post: 03-12-2009, 12:46 PM
  4. shrink and expand nemu when user click
    By rakesh_n_mehta in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-06-2009, 08:02 AM
  5. SwT Expand items problem in Solaris.
    By Sureshgurram in forum SWT / JFace
    Replies: 0
    Last Post: 01-27-2009, 11:23 AM

Posting Permissions

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