Example of sequence Display in jtable

Source: Internet
Author: User

 

Package MRP1;

Import java. AWT. component;
Import java. AWT. dimension;
Import java. AWT. toolkit;
Import java. AWT. event. mouseadapter;
Import java. AWT. event. mouseevent;
Import java. AWT. event. mouselistener;
Import java. util. vector;

Import javax. Swing. imageicon;
Import javax. Swing. jdialog;
Import javax. Swing. jframe;
Import javax. Swing. jlabel;
Import javax. Swing. jscrollpane;
Import javax. Swing. jtable;
Import javax. Swing. Table. defaulttablemodel;
Import javax. Swing. Table. tablecellrenderer;

Public class imageviewtest {
Public static void main (string [] ARGs ){
Jframe frame = new imagviewframe ();
Frame. setdefaclocloseoperation (jframe. exit_on_close );
Frame. setlocation (600,200 );
Frame. setvisible (true );
}
}
Class imagviewframe extends jframe {
Public imagviewframe (){
// Set the frame
Settitle ("imagviewtest ");
Setsize (default_width, default_height );


Vector columnnames = new vector ();
Columnnames. Add ("Index ");
Columnnames. Add ("slice ");
Columnnames. Add ("Description ");
Columnnames. Add ("time ");
Imageicon icon = new imageicon ("D: \ 7.jpg ");
Vector rowdata = new vector ();
Rowdata. Add (1 );
Rowdata. Add (icon );
Rowdata. Add ("July ");
Rowdata. Add ("2011-09-02 ");
Vector cells = new vector ();
Cells. Add (rowdata );


Tablemodel = new mytablemodel (cells, columnnames );
Table = new jtable (tablemodel );
Table. setautoresizemode (jtable. auto_resize_off );
Jscrollpane scrollpane = new jscrollpane (table,
Jscrollpane. vertical_scrollbar_as_needed,
Jscrollpane. horizontal_scrollbar_as_needed );
Add (scrollpane );
}
Private Static final int default_width = 300;
Private Static finals int default_height = 400;
Private mytablemodel tablemodel;
Private jtable table;
}
Class mytablemodel extends defaulttablemodel {
Public mytablemodel (vector cells, vector columnnames ){
Super (cells, columnnames );
}
Public class getcolumnclass (INT col ){
Vector v = (vector) Super. datavector. elementat (0 );
If (V. elementat (COL )! = NULL ){
Return v. elementat (COL). getclass ();
} Else {
Return "". getclass ();
}
}
Public Boolean iscelleditable (INT row, int col ){
Return false;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.