java - JTable with axis -
i'm fiddling around jtable, , want make table has letters a-p row names, , number 1-24 column names (it doesn't matter data type are). not matter if these row , column names inside table or external axis (whatever simpler).
my current attempt name string[]
row , column names, , string[][]
actual content. can't find out how merge valid format creating jtable. current code (that not work) following:
// create table string[] columnnames = {"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24" }; string[] rownames = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p"}; string[][] compoundnames = new string[25][16]; object[][] platedata = {rownames, compoundnames}; table = new jtable(platedata, columnnames); table.setborder(new lineborder(new color(0, 0, 0))); table.setbounds(10, 11, 564, 440); contentpane.add(table);
suggested solutions not have follow concept thought. said, simplest possible way make need, appreciated.
string[][] compoundnames = new string[25][16];
shouldstring[][] compoundnames = new string[16][25];
(no. elementscolumnname
s ,rownames
)for basic informations required read oracle tutorial how use tables
import java.awt.borderlayout; import java.awt.dimension; import java.awt.event.actionevent; import javax.swing.abstractaction; import javax.swing.action; import javax.swing.jframe; import javax.swing.jscrollpane; import javax.swing.jtable; import javax.swing.uimanager; import javax.swing.unsupportedlookandfeelexception; import javax.swing.table.tablemodel; public class tablewithtimer { private jframe frame = new jframe(); private jscrollpane scroll = new jscrollpane(); private jtable mytable; private string[] columnnames = {"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"}; private string[] rownames = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "y", "z"}; private object[][] compoundnames = new string[26][25]; private int count = 1; private javax.swing.timer timer = null; public tablewithtimer() { mytable = new jtable(compoundnames, columnnames); mytable.setautoresizemode(jtable.auto_resize_off); mytable.setpreferredscrollableviewportsize(new dimension(400, 300)); mytable.setshowhorizontallines(true); mytable.setshowverticallines(true); scroll.setviewportview(mytable); frame.add(scroll, borderlayout.center); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.setlocation(100, 100); frame.pack(); frame.setvisible(true); start(); } private void start() { timer = new javax.swing.timer(2500, updatecol()); timer.start(); } public action updatecol() { return new abstractaction("text load action") { private static final long serialversionuid = 1l; @override public void actionperformed(actionevent e) { system.out.println("updating row " + (count + 1)); tablemodel model = mytable.getmodel(); int row = model.getrowcount() - 1;// -1 == leave cell empty @ [0, 0] (int j = 0; j < row; j++) { mytable.changeselection(row, 0, false, false); object value = rownames[j]; model.setvalueat(value, count, 0); count++; if (count >= mytable.getrowcount()) { mytable.changeselection(0, 0, false, false); timer.stop(); system.out.println("update cycle completed"); mytable.clearselection(); } } } }; } public static void main(string args[]) { try { (uimanager.lookandfeelinfo info : uimanager.getinstalledlookandfeels()) { //system.out.println(info.getname()); if ("nimbus".equals(info.getname())) { uimanager.setlookandfeel(info.getclassname()); break; } } } catch (unsupportedlookandfeelexception e) { // handle exception } catch (classnotfoundexception e) { // handle exception } catch (instantiationexception e) { // handle exception } catch (illegalaccessexception e) { // handle exception } tablewithtimer tablewithtimer = new tablewithtimer(); } }
Comments
Post a Comment