java - JTable add rows bottom up - rows added one after the other should appear at the bottom of the last one but all should be bottom aligned -
i have jtable in java swing needs bottom aligned.
as in normal tables when row added table placed on top, when next row added added under , on.
what place new row @ bottom of table. when new row added new row placed right @ bottom , previous row move up. way rows appear move upward. rows should stick bottom.
any ideas how this?
you can use decorator pattern. assuming class named tablemodeldecorator decorates tablemodel can implement:
public class tableemptyreverserowsmodel extends tablemodeldecorator { private int minimumrows; public tableemptyreverserowsmodel(final tablemodel realmodel, final int minimumrows) { super(realmodel); this.minimumrows = minimumrows; } public int getrowcount() { int realcount = model.getrowcount(); return realcount < minimumrows ? minimumrows : realcount; } public boolean iscelleditable(int rowindex, int columnindex) { int diff = minimumrows - model.getrowcount(); if (diff > 0) { if (rowindex < diff) { return false; } else { return model.iscelleditable(rowindex - diff, columnindex); } } else { return model.iscelleditable(rowindex, columnindex); } } public object getvalueat(int rowindex, int columnindex) { int diff = minimumrows - model.getrowcount(); if (diff > 0) { if (rowindex < diff) { return null; } else { return model.getvalueat(rowindex - diff, columnindex); } } else { return model.getvalueat(rowindex, columnindex); } } public void setvalueat(object avalue, int rowindex, int columnindex) { int diff = minimumrows - model.getrowcount(); if (diff > 0) { if (rowindex < diff) { } else { super.setvalueat(avalue, rowindex - diff, columnindex); } } else { super.setvalueat(avalue, rowindex, columnindex); } } }
be aware of cell renderer must handle null value ;)
see ya!
Comments
Post a Comment