swing - JTable doesn't show all over in JFrame in java -
i have jtable
add jpanel
. add jpanel
jframe
called frame. frame
show table when maximize window jpanel
still remains small size. want show jpanel
on frame when maximize frame. here code:
import java.awt.borderlayout; import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.resultsetmetadata; import java.sql.statement; import java.util.vector; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.jscrollpane; import javax.swing.jtable; @suppresswarnings("serial") public class testclass extends jpanel { public testclass() { vector columnnames = new vector(); vector data = new vector(); int columns =3; // column names columnnames.addelement("id"); columnnames.addelement("name"); columnnames.addelement("age"); // row data vector row = new vector(columns); row.addelement("1"); row.addelement("moshi"); row.addelement("22"); data.addelement( row ); // create table database data jtable table = new jtable(data, columnnames) { public class getcolumnclass(int column) { (int row = 0; row < getrowcount(); row++) { object o = getvalueat(row, column); if (o != null) { return o.getclass(); } } return object.class; } }; jscrollpane scrollpane = new jscrollpane( table ); add(scrollpane); } public static void main(string[] args) { testclass testclass = new testclass(); //**jpanel** jframe frame = new jframe(); frame.setsize(500, 600); frame.getcontentpane().add(testclass); //**add jpanel frame** frame.setvisible(true); } }
use layout manager sizes components according available size rather jpanel's
default flowlayout
uses components preferred size, e.g.
setlayout(new gridlayout());
Comments
Post a Comment