swing - new java table more usefull than JTable -
some days ago have glimpse.
with headache comes in moment when need work jtable, , have seen utility of jsplitpane, think idea, sincere, don't know start reach result.
the result want, , maybe other people, table created jscrollpane + jpanel + jsplitpane + gridbaglayout + others components, hope can put other components jbutton, images or else want, because phisical cells want jpanel.
here example respectable list, in opinion, find on forum:
import java.awt.borderlayout; import java.awt.color; import java.awt.dimension; import java.awt.eventqueue; import java.awt.gridbagconstraints; import java.awt.gridbaglayout; import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.boxlayout; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; import javax.swing.jscrollpane; import javax.swing.swingutilities; import javax.swing.uimanager; import javax.swing.unsupportedlookandfeelexception; import javax.swing.border.matteborder; public class dynamicpanellist { public static void main(string[] args) { new dynamicpanellist(); } public dynamicpanellist() { eventqueue.invokelater(new runnable() { @override public void run() { try { uimanager.setlookandfeel(uimanager.getsystemlookandfeelclassname()); } catch (exception ex) { } jframe frame = new jframe("test"); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.add(new listpane()); frame.pack(); frame.setlocationrelativeto(null); frame.setvisible(true); } }); } public class listpane extends jpanel { private jpanel mainlist; public listpane() { setlayout(new borderlayout()); this.mainlist = new jpanel(new gridbaglayout()); gridbagconstraints gbc = new gridbagconstraints(); gbc.gridwidth = gridbagconstraints.remainder; gbc.weightx = 1; gbc.weighty = 1; this.mainlist.add(new jpanel(), gbc); this.add(new jscrollpane(mainlist)); jbutton add = new jbutton("add"); add.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent e) { jpanel panel = new jpanel(); panel.add(new jlabel("hello")); panel.setborder(new matteborder(0, 0, 1, 0, color.gray)); gridbagconstraints gbc = new gridbagconstraints(); gbc.gridwidth = gridbagconstraints.remainder; gbc.weightx = 1; gbc.fill = gridbagconstraints.horizontal; listpane.this.mainlist.add(panel, gbc, 0); listpane.this.validate(); listpane.this.repaint(); } }); add(add, borderlayout.south); } @override public dimension getpreferredsize() { return new dimension(200, 200); } } }
at code want add features add header(not difficult), difficult part add columns can resized. here section guess need use jsplitpane. if ideea wrong, please comment , if have ideea, small one, please share us.
next days, i'll try add more code here explain more detailed idea.
thanks, , i'm sorry "cave" english skill.
to me looks want use jtable layout swing components using html table layout page (which not idea nowdays).
if true gridbaglayout (without using jsplitpanes) friend. if want have excel table should use jtable.
there plenty of tutorials swing components oracle.
Comments
Post a Comment