🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: be.comp.programming
Article #2578

[Java] GridBagLayout.

#2578
From: Simonne De Ryck
Date: Thu, 22 Apr 2004 17:31
93 lines
3999 bytes
Hallo,

Ik heb problemen met het de layout van mijn scherm.
Mijn bedoeling is om bovenaan op het scherm een tabel te maken en onderaan
een knop om het scherm te verlaten.
Het probleem is het volgende: als je de code die hieronder staat uitvoert
zul je merken dat mij dat al redelijk goed gelukt is.  Nu als ik dit scherm
verklein of vergroot is de bedoeling dat de tabel mee vergroot of verkleint
en dit gebeurt niet zoals het hoort.

Ik hoop dat hier iemand is die mij kan helpen met dit probleem.

Alvast bedankt & groetjes
Els

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class SearchClient extends JFrame implements ActionListener {
    public JTable aTable;
    public JScrollPane aScrollPane;
    public static String [][] tableData = {{"Lijn1", "Lijn1", "Lijn1"},
                                                        {"Lijn2", "Lijn2",
"Lijn2"},
                                                        {"Lijn3", "Lijn3",
"Lijn3"}};
    public static String[] columnHeadings = {"Naam", "Adres", "Gemeente"};
    private JButton Exit;
    private JLabel Label1, Label2;

    public SearchClient() {
        // ----- Opbouw scherm -----
        Dimension scrSize= Toolkit.getDefaultToolkit().getScreenSize();
        this.setTitle("Zoeken");
        this.setSize(500, 200);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLocation((scrSize.width - 500)/2, (scrSize.height - 200)/2);
        this.isResizable();

        aTable = new JTable(tableData, columnHeadings);
        aScrollPane = new JScrollPane(aTable);

        Exit = new JButton();
        Exit.setText("Verlaten");
        Exit.addActionListener(this);

        Label1 = new JLabel();
        Label1.setText(" ");
        Label2 = new JLabel();
        Label2.setText(" ");

        GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();
        getContentPane().setLayout(gridbag);
        c.gridwidth = GridBagConstraints.REMAINDER;
        c.weightx = 0.0;
        c.gridheight = 1;
        gridbag.setConstraints(Label1, c);
        getContentPane().add(Label1);

        c.gridwidth = GridBagConstraints.REMAINDER;
        c.weightx = 0.0;
        c.gridheight = 0;
        gridbag.setConstraints(aTable, c);
        getContentPane().add(aScrollPane);

        c.gridwidth = GridBagConstraints.REMAINDER;
        c.weightx = 0.0;
        c.gridheight = 1;
        gridbag.setConstraints(Label2, c);
        getContentPane().add(Label2);

        c.gridwidth = GridBagConstraints.WEST;
        c.weightx = 1.0;
        gridbag.setConstraints(Exit, c);
        getContentPane().add(Exit);

        pack();
        setVisible(true);
    }

    public static void main(String[] args){
        new SearchClient();
    }

    public void actionPerformed(ActionEvent e){
        if(e.getSource() == Exit){
            System.exit(0);
        }
    }
}
Technical Details
Message-ID: <40880182$0$10819$a0ced6e1@news.skynet.be>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!t-online.de!skynet.be!newspost001!tjb!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: DUTCH,ASCII-7-bit
X-Google-Thread: fcea4,75e01c706c0b7fe5,start
X-Google-Attributes: gidfcea4,public
X-Google-ArrivalTime: 2004-04-22 10:31:47 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!t-online.de!skynet.be!newspost001!tjb!not-for-mail
From: "Simonne De Ryck" <simonne.deryck@skynet.be>
Newsgroups: be.comp.programming
Subject: [Java] GridBagLayout.
Date: Thu, 22 Apr 2004 19:31:56 +0200
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Lines: 95
Message-ID: <40880182$0$10819$a0ced6e1@news.skynet.be>
Organization: -= Belgacom Usenet Service =-
NNTP-Posting-Host: 81.240.171.164
X-Trace: 1082655106 newsread003.isp.belgacom.be 10819 81.240.171.164:1361
X-Complaints-To: usenet-abuse@skynet.be