Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it L'avatar di Alex'87
    Registrato dal
    Aug 2001
    residenza
    Verona
    Messaggi
    5,802

    GridBagLayout e resize finestra

    Buonasera,
    sto facendo qualche esperimento con il GridBagLayout e mi sto imbattendo in un problemino.

    Nello screenshot si vede quello che ottengo dal codice che ho postato qui sotto.



    Il mio problema è che non riesco a fare in modo che il JEditorPane segua le dimensioni della finestra. Al momento infatti ha delle dimensioni che non cambiano col in resize della finestra: mettendo a tutto schermo la finestra, il pannello non cresce e resta delle stesse dimensioni, lasciando enormi spazi vuoti sopra e sotto.
    Ho già messo c.fill = GridBagConstraints.BOTH; ma non basta.

    Qualche idea? Cosa mi sfugge? Grazie

    codice:
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    
    import javax.swing.JComboBox;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.JEditorPane;
    import javax.swing.ScrollPaneConstants;
    
    public class EditorPanel extends JPanel
    {
        public EditorPanel()
        {
            setLayout(new GridBagLayout());
    
            GridBagConstraints c = new GridBagConstraints();
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 0;
            c.gridy = 0;
            c.insets = new Insets(2, 2, 2, 2);
            add(pathLabel, c);
    
            c = new GridBagConstraints();
            c.fill = GridBagConstraints.HORIZONTAL;
            c.weightx = 0.5;
            c.gridx = 1;
            c.gridy = 0;
            c.insets = new Insets(2, 2, 2, 2);
            c.gridwidth = GridBagConstraints.REMAINDER;
            add(path, c);
    
            c = new GridBagConstraints();
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 0;
            c.gridy = 1;
            c.insets = new Insets(2, 2, 2, 2);
            add(nameLabel, c);
    
            c = new GridBagConstraints();
            c.fill = GridBagConstraints.HORIZONTAL;
            c.weightx = 0.5;
            c.gridx = 1;
            c.gridy = 1;
            c.insets = new Insets(2, 2, 2, 2);
            c.gridwidth = GridBagConstraints.REMAINDER;
            add(name, c);
    
            c = new GridBagConstraints();
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 0;
            c.gridy = 2;
            c.insets = new Insets(2, 2, 2, 2);
            add(syntaxLabel, c);
    
            c = new GridBagConstraints();
            c.fill = GridBagConstraints.HORIZONTAL;
            c.weightx = 0.5;
            c.gridx = 1;
            c.gridy = 2;
            c.insets = new Insets(2, 2, 2, 2);
            c.gridwidth = GridBagConstraints.REMAINDER;
            add(syntax, c);
    
            c = new GridBagConstraints();
            c.fill = GridBagConstraints.HORIZONTAL;
            c.gridx = 0;
            c.gridy = 3;
            c.insets = new Insets(2, 2, 2, 2);
            c.anchor = GridBagConstraints.BASELINE;
            add(editorLabel, c);
    
            c = new GridBagConstraints();
            c.fill = GridBagConstraints.BOTH;
            c.weightx = 0.5;
            c.gridx = 1;
            c.gridy = 3;
            c.ipady = 200;
            c.insets = new Insets(2, 2, 2, 2);
            c.gridwidth = GridBagConstraints.REMAINDER;
            add(new JScrollPane(editor,
                    ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), c);
    
            c = new GridBagConstraints();
            c.fill = GridBagConstraints.HORIZONTAL;
            c.ipadx = 2;
            c.gridx = 0;
            c.gridy = 4;
            c.insets = new Insets(2, 2, 2, 2);
            c.anchor = GridBagConstraints.BASELINE;
            add(commentLabel, c);
    
            c = new GridBagConstraints();
            c.fill = GridBagConstraints.HORIZONTAL;
            c.weightx = 0.5;
            c.gridx = 1;
            c.gridy = 4;
            c.ipady = 50;
            c.insets = new Insets(2, 2, 2, 2);
            c.gridwidth = GridBagConstraints.REMAINDER;
            add(new JScrollPane(comment,
                    ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), c);
    
            c = new GridBagConstraints();
            c.fill = GridBagConstraints.HORIZONTAL;
            c.ipadx = 2;
            c.gridx = 0;
            c.gridy = 5;
            c.insets = new Insets(2, 2, 2, 2);
            add(tagsLabel, c);
    
            c = new GridBagConstraints();
            c.fill = GridBagConstraints.HORIZONTAL;
            c.weightx = 0.5;
            c.gridx = 1;
            c.gridy = 5;
            c.insets = new Insets(2, 2, 2, 2);
            c.gridwidth = GridBagConstraints.REMAINDER;
            add(tags, c);
        }
    
        JTextField path = new JTextField();
        JTextField name = new JTextField();
        JTextField tags = new JTextField();
        JComboBox syntax = new JComboBox();
        JEditorPane editor = new JEditorPane ();
        JTextArea comment = new JTextArea();
    
        JLabel pathLabel = new JLabel("Categories:", JLabel.RIGHT);
        JLabel nameLabel = new JLabel("Name:", JLabel.RIGHT);
        JLabel tagsLabel = new JLabel("Tags:", JLabel.RIGHT);
        JLabel syntaxLabel = new JLabel("Syntax:", JLabel.RIGHT);
        JLabel editorLabel = new JLabel("Code:", JLabel.RIGHT);
        JLabel commentLabel = new JLabel("Comment:", JLabel.RIGHT);
    
        private static final long serialVersionUID = 2099888665427331067L;
    }
    SpringSource Certified Spring Professional | Pivotal Certified Enterprise Integration Specialist
    Di questo libro e degli altri (blog personale di recensioni libri) | ​NO M.P. TECNICI

  2. #2
    Utente di HTML.it L'avatar di Alex'87
    Registrato dal
    Aug 2001
    residenza
    Verona
    Messaggi
    5,802
    Mi autorispondo: molto semplicemente avevo dimenticato di settare anche il valore weighty dei vari componenti

    Risolto ^^
    SpringSource Certified Spring Professional | Pivotal Certified Enterprise Integration Specialist
    Di questo libro e degli altri (blog personale di recensioni libri) | ​NO M.P. TECNICI

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.