java - JTable won't span up to JFrame's borders -
java - JTable won't span up to JFrame's borders -
i can't create table span jframe border. tried using setminimumsize
didn't work. missing?
added: i'm not interested in adding jscrollpane table (yet). want know how create gridbaglayout resize particular component jframe's borders.
public class ost extends jframe{ ostbridge bridge; public ost() { container cp=this.getcontentpane(); gridbagconstraints c=new gridbagconstraints(); cp.setlayout(new gridbaglayout()); // add together button jbutton b1=new jbutton("button"); c.gridx=0; c.gridy=0; c.insets=new insets(20,0,20,0); cp.add(b1,c); // table info string[] columns={"album","url"}; object[][] data={ {"test1","tes2"} }; // add together table jtable table=new jtable(data,columns); c.gridx=0; c.gridy=1; c.weightx=1; c.weighty=1; c.gridwidth=c.remainder; table.setbackground(color.red); table.setminimumsize(new dimension(400,400)); cp.add(table, c); // show this.setdefaultcloseoperation(exit_on_close); this.setsize(320, 240); this.settitle("test"); this.setvisible(true); }
this get:
and get:
in constraints table should've used gridbagconstraints.fill
:
// add together table jtable table=new jtable(data,columns); c.gridx=0; c.gridy=1; c.weightx=1; c.weighty=1; c.gridwidth=c.remainder; c.fill=gridbagconstraints.horizontal; // line solves problem table.setbackground(color.red); table.setminimumsize(new dimension(400,400)); cp.add(table, c);
hope reply helps else who's trying give firsts steps java me! :)
java swing layout-manager gridbaglayout
Comments
Post a Comment