🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #507

JTable

#507
From: m3w316
Date: Tue, 26 Jul 2005 20:04
53 lines
2701 bytes
I have created a JTable.  However if my table gets too big or if i
resize the application window, the horizontal scrollbar does not appear
at all. The vertical scrollbar works fine. I'm using eclipse. Heres a
copy of the code i'm working with:

import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.ScrollPaneConstants;

import java.awt.*;
import java.awt.event.*;

public class SimpleTable extends JFrame {

  public SimpleTable() {
      super("Personnel");

      Object[][] data = {
          {"Thomas", "Albanese", "Engineer",
                 "Development", new Integer(10)},
          {"Laura", "Bates", "Administrator",
                     "Benefits", new Integer(4)},
          {"Susan", "Carson", "Director",
                   "Marketing", new Integer(12)},
          {"William", "Delancy", "Instructor",
                     "Support", new Integer (6)}
      };

      String[] columnNames = {"First Name",
                              "Last Name",
                              "Job Title",
                              "Department",
                              "Service (yrs)"};

      JTable perstab = new JTable(data, columnNames);
      perstab.setPreferredScrollableViewportSize(
                             new Dimension(500, 65));
      JScrollPane scrollPane = new JScrollPane(perstab,
      		ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
			ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

      getContentPane().add(scrollPane,BorderLayout.CENTER);

  }

  public static void main(String[] args) {
      SimpleTable frame = new SimpleTable();
      frame.pack();
      frame.setVisible(true);
  }
}
Technical Details
Message-ID: <1122408276.953155.67510@f14g2000cwb.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,4ec755ed3eba7f9,start
X-Google-Attributes: gid111d45,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!f14g2000cwb.googlegroups.com!not-for-mail
From: m3w316@gmail.com
Newsgroups: borland.public.jbuilder.java.swing
Subject: JTable
Date: 26 Jul 2005 13:04:36 -0700
Organization: http://groups.google.com
Lines: 54
Message-ID: <1122408276.953155.67510@f14g2000cwb.googlegroups.com>
NNTP-Posting-Host: 63.204.242.245
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1122408282 17411 127.0.0.1 (26 Jul 2005 20:04:42 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 26 Jul 2005 20:04:42 +0000 (UTC)
User-Agent: G2/0.2
Complaints-To: groups-abuse@google.com
Injection-Info: f14g2000cwb.googlegroups.com; posting-host=63.204.242.245;
   posting-account=0n2sUA0AAACTsJP7HOg-iCk5cyxHWHIK