java - JTable Clickable Header in swing -


this question has answer here:

hello have hard time solving puzzle. professor gave code , told change make column head clickable.can change me.? wasted 4 hours :( not great in java swings below code... below code :

package academic.emailclient.view;  import java.awt.color; import java.awt.dimension; import java.awt.font; import java.util.arraylist; import java.util.date; import java.util.vector; import javax.swing.*; import javax.swing.table.*; import academic.emailclient.model.message; import academic.emailclient.view.entities.messageview;  public class mailbox extends jframe {   jtable tableinbox;   private final int mailbox_frame_width = 1080;   private final int mailbox_frame_height = 650;   static final boolean visible = true;  public mailbox() {     object[] columnnamesinbox = { "boolean", "sender", "subject", "body" };     object[][] datainbox = {             { false, "5@gmail.com", "d", "t" },             { false, "r@gmail.com", "projhsdject work", "i " },             { false, "r.@ymail.com", "job placement","iut that" },             { true, "yam@gmail.com", "s1", "as" }             };      defaulttablemodel modelinbox = new defaulttablemodel(datainbox,             columnnamesinbox);     tableinbox = new jtable(modelinbox) {          @override         public class getcolumnclass(int columninbox) {             switch (columninbox) {             case 0:                 return boolean.class;             case 1:                 return string.class;             case 2:                 return string.class;             case 3:                 return string.class;             default:                 return boolean.class;             }         }     };         tableinbox.setbackground(color.lightgray);     tableinbox.setgridcolor(new color(0,128,0));     jtableheader inboxheader = tableinbox.gettableheader();     inboxheader.setbackground(color.dark_gray);     inboxheader.setforeground(color.white);  }   public int getmesssagescount(int i) {     return 0; }  public int getcheckeditemsnumber(int i) {     return 0; }  public object[][] getcheckeditems() {      return getcheckeditems(); }  public object[][] getmail() {     return getmail(); }  public object[][] orderbydate() {      return orderbydate(); }  public object[][] orderbysender() {     return orderbysender(); }  public object[][] orderbysubject() {     return orderbysubject(); }  public jtable getmailbox() {     return tableinbox; }   public void run() {      jframe mailboxframe = new jframe();      mailboxframe.setmaximumsize(new dimension(mailbox_frame_width, mailbox_frame_height));     mailboxframe.setpreferredsize(new dimension(mailbox_frame_width, mailbox_frame_height));     mailboxframe.setbounds(0, 0, mailbox_frame_width, mailbox_frame_height);     mailboxframe.setvisible(visible);     mailboxframe.setdefaultcloseoperation(jframe.exit_on_close); }  } 

professor gave code , told change make column head clickable

see jtable.setautocreaterowsorter(true). e.g. might see after clicking cat. column header. small upwards pointing arrow indicates table sorted on column.

clickable table header


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -