Results 1 to 4 of 4

Thread: GroupLayout

  1. #1
    Itun is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Default GroupLayout

    I want to use two layout depending on circumstances. But when I build them in the constructor and save, when I use them they don`t work. When I build them every time before using it is work.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default

    You'll probably receive faster and more constructive feedback if you provide more of a description - especially something in the form of an SSCCE with a clear definition of what you mean by 'doesn't work'.

  3. #3
    Itun is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Default

    It works:
    {
    GroupLayout groupLayout = new GroupLayout(jPanel);
    groupLayout.setHorizontalGroup(
    groupLayout.createParallelGroup(GroupLayout.Alignm ent.LEADING).
    addComponent(jLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE));
    groupLayout.setVerticalGroup(
    groupLayout.createParallelGroup(GroupLayout.Alignm ent.LEADING).
    addComponent(jLabel, GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE));
    jPanel.setLayout(groupLayout);
    }
    It does not work:
    GroupLayout groupLayout;
    {
    groupLayout = new GroupLayout(jPanel);
    groupLayout.setHorizontalGroup(
    groupLayout.createParallelGroup(GroupLayout.Alignm ent.LEADING).
    addComponent(jLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE));
    groupLayout.setVerticalGroup(
    groupLayout.createParallelGroup(GroupLayout.Alignm ent.LEADING).
    addComponent(jLabel, GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE));
    }
    .
    .
    .
    {
    jPanel.setLayout(groupLayout);
    }
    I want to create a panel with Open/Close Button. May be there are another good variant how to create this panel without changing layout. For example, when I change size it is not appropriate, because size is changed from right to left and it covers my button.
    Last edited by Itun; 03-24-2011 at 05:31 AM.

  4. #4
    Itun is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Default

    I suppose It is not also understandable.
    I wrote a class.
    import java.awt.LayoutManager;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;

    public class LayoutTest extends JFrame {

    public LayoutTest() {
    initComponents();
    }

    private void initComponents() {

    jPanel1 = new javax.swing.JPanel();

    jPanel1.setBackground(new java.awt.Color(204, 204, 255));
    jPanel1.setBorder(javax.swing.BorderFactory.create EtchedBorder());

    jButton.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {
    LayoutManager tempGroupLayout = jPanel1.getLayout();
    jPanel1.setLayout(layoutManager2);
    layoutManager = layoutManager2;
    layoutManager2 = tempGroupLayout;
    }
    });

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING).
    addGroup(javax.swing.GroupLayout.Alignment.TRAILIN G, jPanel1Layout.createSequentialGroup().
    addContainerGap(286, Short.MAX_VALUE).
    addComponent(jButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)));
    jPanel1Layout.setVerticalGroup(
    jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING).
    addComponent(jButton, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE));
    layoutManager = jPanel1Layout;

    javax.swing.GroupLayout jPanel1Layout2 = new javax.swing.GroupLayout(jPanel1);
    jPanel1Layout2.setHorizontalGroup(
    jPanel1Layout2.createParallelGroup(javax.swing.Gro upLayout.Alignment.LEADING).
    addGroup(javax.swing.GroupLayout.Alignment.TRAILIN G, jPanel1Layout2.createSequentialGroup().
    addComponent(jButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)));
    jPanel1Layout2.setVerticalGroup(
    jPanel1Layout2.createParallelGroup(javax.swing.Gro upLayout.Alignment.LEADING).
    addComponent(jButton, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE));
    layoutManager2 = jPanel1Layout2;
    pack();
    }

    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {

    public void run() {
    new LayoutTest().setVisible(true);
    }
    });
    }
    private JButton jButton;
    private JPanel jPanel1;
    private LayoutManager layoutManager;
    private LayoutManager layoutManager2;
    }

Similar Threads

  1. GroupLayout Issue
    By m_patten2 in forum AWT / Swing
    Replies: 2
    Last Post: 11-10-2010, 10:50 PM
  2. Anyone know how GroupLayout works?
    By ProgrammingPup in forum Advanced Java
    Replies: 5
    Last Post: 12-01-2009, 11:12 PM
  3. Doubt with GroupLayout
    By emylyano3 in forum AWT / Swing
    Replies: 1
    Last Post: 06-28-2009, 02:16 AM
  4. help about class GroupLayout
    By MaHa in forum NetBeans
    Replies: 2
    Last Post: 09-07-2008, 11:25 PM
  5. [SOLVED] Alignment in GroupLayout
    By nanou in forum AWT / Swing
    Replies: 8
    Last Post: 09-03-2008, 03:14 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
  •