MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JViewport;

public class MainClass {

    public static void main(final String args[]) {
        final Object rows[][] = { { "one", "1" }, { "two", "2" }, { "three", "3" } };
        final Object headers[] = { "English", "Digit" };

        JFrame frame = new JFrame("Scrollless Table");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JTable table = new JTable(rows, headers);

        JScrollPane scrollPane = new JScrollPane(table);
        JViewport viewport = new JViewport();
        viewport.setView(table);
        scrollPane.setColumnHeaderView(new JLabel("table header here"));
        scrollPane.setRowHeaderView(viewport);

        frame.add(scrollPane, BorderLayout.CENTER);
        frame.setSize(300, 150);
        frame.setVisible(true);
    }
}