Results 1 to 2 of 2
  1. #1
    Marcoita_88 is offline Member
    Join Date
    Aug 2011
    Location
    Italy
    Posts
    9
    Rep Power
    0

    Default Gridbaglayout, hint on label alignment...

    Hello,
    I have read the gridbaglayout tutorial, and it was very useful, but I have a problem with 4 labels.
    In the blue labels (1) (3) (4) I set maximum and minimum size, but the labels risize itself...
    In the White label (2) the text is dinamic and it should resize the white label.
    If I set a minimum size, the white label become of fixed size and the text can be not full displayed. How can I set a minimum vertical size wiithout set a maximum vertical size on label (2)?
    Here is an example:
    http://imageshack.us/photo/my-images...zeproblem.png/
    http://imageshack.us/photo/my-images/834/nostate.png/
    And here is the initComponents code:
    Java Code:
    private void initComponents() {
            java.awt.GridBagConstraints gridBagConstraints;
    
            labelImmagine = new javax.swing.JLabel();
            labelNomeCompleto = new javax.swing.JLabel();
            labelStatoChat = new javax.swing.JLabel();
            taMioTesto = new javax.swing.JScrollPane();
            taInviaMessaggi = new javax.swing.JTextArea();
            jScrollPane1 = new javax.swing.JScrollPane();
            teResocontoMessaggi = new javax.swing.JEditorPane();
            labelScrittaStato = new javax.swing.JLabel();
            labelStatoFacebook = new javax.swing.JLabel();
    
            setMinimumSize(new java.awt.Dimension(500, 200));
            getContentPane().setLayout(new java.awt.GridBagLayout());
    
            labelImmagine.setBackground(new java.awt.Color(255, 255, 255));
            labelImmagine.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
            labelImmagine.setText("Immagine");
            labelImmagine.setOpaque(true);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 0;
            gridBagConstraints.gridheight = 3;
            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
            gridBagConstraints.ipadx = 15;
            gridBagConstraints.ipady = 15;
            getContentPane().add(labelImmagine, gridBagConstraints);
    
            labelNomeCompleto.setBackground(new Color(0x6D84B4));
            labelNomeCompleto.setForeground(new java.awt.Color(255, 255, 255));
            labelNomeCompleto.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
            labelNomeCompleto.setText("jLabel1");
            labelNomeCompleto.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 10, 1, 1));
            labelNomeCompleto.setMaximumSize(new java.awt.Dimension(45, 20));
            labelNomeCompleto.setMinimumSize(new java.awt.Dimension(45, 20));
            labelNomeCompleto.setOpaque(true);
            labelNomeCompleto.setPreferredSize(new java.awt.Dimension(45, 20));
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 1;
            gridBagConstraints.gridy = 0;
            gridBagConstraints.gridwidth = 2;
            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
            gridBagConstraints.weightx = 1.0;
            getContentPane().add(labelNomeCompleto, gridBagConstraints);
    
            labelStatoChat.setBackground(new Color(0x6D84B4));
            labelStatoChat.setForeground(new java.awt.Color(255, 255, 255));
            labelStatoChat.setText("jLabel3");
            labelStatoChat.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 10, 1, 1));
            labelStatoChat.setMaximumSize(new java.awt.Dimension(45, 20));
            labelStatoChat.setMinimumSize(new java.awt.Dimension(45, 20));
            labelStatoChat.setOpaque(true);
            labelStatoChat.setPreferredSize(new java.awt.Dimension(45, 20));
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 2;
            gridBagConstraints.gridy = 2;
            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
            gridBagConstraints.ipadx = 15;
            gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_END;
            gridBagConstraints.weightx = 1.0;
            getContentPane().add(labelStatoChat, gridBagConstraints);
    
            taMioTesto.setMinimumSize(new java.awt.Dimension(23, 50));
    
            taInviaMessaggi.setColumns(20);
            taInviaMessaggi.setRows(3);
            taInviaMessaggi.addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyPressed(java.awt.event.KeyEvent evt) {
                    taInviaMessaggiKeyPressed(evt);
                }
                public void keyReleased(java.awt.event.KeyEvent evt) {
                    taInviaMessaggiKeyReleased(evt);
                }
            });
            taMioTesto.setViewportView(taInviaMessaggi);
    
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 1;
            gridBagConstraints.gridy = 4;
            gridBagConstraints.gridwidth = 2;
            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
            gridBagConstraints.anchor = java.awt.GridBagConstraints.LAST_LINE_END;
            getContentPane().add(taMioTesto, gridBagConstraints);
    
            jScrollPane1.setMinimumSize(new java.awt.Dimension(80, 100));
            jScrollPane1.setPreferredSize(new java.awt.Dimension(80, 100));
    
            teResocontoMessaggi.setContentType("text/html");
            teResocontoMessaggi.setEditable(false);
            teResocontoMessaggi.setText("<html>\r\n  <head>\r\n\r    <LINK href=\"http://facebookdeskchat.altervista.org/stileChat.css\" rel=\"stylesheet\" type=\"text/css\">\n  </head>\r\n  <body>\r</body>\r\n</html>\r\n");
            jScrollPane1.setViewportView(teResocontoMessaggi);
    
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 1;
            gridBagConstraints.gridy = 3;
            gridBagConstraints.gridwidth = 2;
            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
            gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END;
            gridBagConstraints.weightx = 1.0;
            gridBagConstraints.weighty = 1.0;
            getContentPane().add(jScrollPane1, gridBagConstraints);
    
            labelScrittaStato.setBackground(new Color(0x6D84B4));
            labelScrittaStato.setForeground(new java.awt.Color(255, 255, 255));
            labelScrittaStato.setText("Stato:");
            labelScrittaStato.setMinimumSize(new java.awt.Dimension(70, 14));
            labelScrittaStato.setOpaque(true);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 1;
            gridBagConstraints.gridy = 2;
            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
            getContentPane().add(labelScrittaStato, gridBagConstraints);
    
            labelStatoFacebook.setBackground(new java.awt.Color(255, 255, 255));
            labelStatoFacebook.setText("label stato facebook");
            labelStatoFacebook.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 10, 1, 1));
            labelStatoFacebook.setMinimumSize(new java.awt.Dimension(108, 30));
            labelStatoFacebook.setOpaque(true);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 1;
            gridBagConstraints.gridy = 1;
            gridBagConstraints.gridwidth = 2;
            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
            gridBagConstraints.weightx = 1.0;
            getContentPane().add(labelStatoFacebook, gridBagConstraints);
    
            pack();
        }// </editor-fold>
    Last edited by Marcoita_88; 08-09-2011 at 08:17 PM.

  2. #2
    Marcoita_88 is offline Member
    Join Date
    Aug 2011
    Location
    Italy
    Posts
    9
    Rep Power
    0

    Default more clear request

    Sorry, maybe in the first post i'm not clear on what di I want.
    Look the following image:

    ImageShack® - Online Photo and Video Hosting

    I want the second blue line, with the text "Stato" and the green icon, to be always the same height of the first blue line, and not taller as in the image.

Similar Threads

  1. Help with alignment
    By firecat318 in forum AWT / Swing
    Replies: 3
    Last Post: 05-25-2010, 03:01 AM
  2. Replies: 0
    Last Post: 01-14-2009, 01:26 PM
  3. Methods - give hint
    By iWonder in forum New To Java
    Replies: 25
    Last Post: 01-07-2009, 02:34 PM
  4. Label Alignment Example
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 07:49 PM
  5. code hint scroll bar ?
    By tryit in forum Eclipse
    Replies: 3
    Last Post: 04-28-2008, 07:07 AM

Tags for this Thread

Posting Permissions

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