KidsLovePC Contact Us
  Home   PHP  Graphics ASP  JavaScript   J2EE  HTML  JAVA   Swing   Webtip  Forums  Lyric  Free sheet music  Ringtones
java,jtable,jtree,swing Return to JAVA table list

Best books about JAVA programming:

JAVA JTable fixed column

The following code demos how to fix the first 2 columns in JTtable.

//The example in following link doesn't work
//Example is modified from
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;

public class FixedColumnExample extends JFrame {
Object[][] data;
Object[] column;
JTable fixedTable,table;

public FixedColumnExample() {
super( "Fixed Column Example" );
setSize( 400, 150 );

data = new Object[][]{
column = new Object[]{"FirstFixed","LastFixed","a","b","c","d","e","f"};

AbstractTableModel fixedModel = new AbstractTableModel() {
public int getColumnCount() { return 2; }
public int getRowCount() { return data.length; }
public String getColumnName(int col) {
return (String)column[col];
public Object getValueAt(int row, int col) {
return data[row][col];
AbstractTableModel model = new AbstractTableModel() {
public int getColumnCount() { return column.length -2; }
public int getRowCount() { return data.length; }
public String getColumnName(int col) {
return (String)column[col +2];
public Object getValueAt(int row, int col) {
return data[row][col+2];
public void setValueAt(Object obj, int row, int col) {
data[row][col +2] = obj;
public boolean CellEditable(int row, int col) {
return true;

fixedTable = new JTable( fixedModel );

table = new JTable( model );


JScrollPane scroll = new JScrollPane( table );
JViewport viewport = new JViewport();

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

public static void main(String[] args) {
FixedColumnExample frame = new FixedColumnExample();
frame.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {


Sponsored link
Java JTabbedPane
JTabbedPane Preview List
Java JComboBox
JComboBox Preview List
Java JTooltip
JTooltip Preview List
Java JList
JList Preview List
Java JTree
JTree Preview List 1
JTree Preview List 2
JTable Preview List 1
JTable Preview List 2
JTable Preview List 3
JTable Preview List 4
JTable Preview List 5
JTable Preview List 6
JTable Preview List 7
JAVA Jslide
JSlide Preview List



Best books about JAVA programming from Amazon
Professional Java, JDK 5 Edition (Paperback Simply Java Programming: An Application-Driven Tutorial Approach (Paperback) Effective Java Programming Language Guide (Paperback) Head First Java, 2nd Edition (Paperback) Java : An Introduction to Problem Solving and Programming (4th Edition)


Printer Inkjet A Z lyricsLearn ChineseHome|PHP|Swing|HTML|JavaScript|ASP|JAVA|Forum|WebTip|Contact Us
Copyright © All rights reserved(new). Privacy|Copyright
designed by

Please help us cover the web site maintenance fee.
barcode scanner Thermal Printer credit card machine bar code printer