JViewport: setView(Component com) : JViewport « javax.swing « Java by API





JViewport: setView(Component com)

 
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);
  }
}

           
         
  










Related examples in the same category

1.new JViewport()
2.JViewport: setViewPosition(Point p)