java - Adding JScrollPane to JTable doesn't show up -
i'm pretty new javas swings, sorry if trivial. constructor, excluded unnecessary form items. (i tried running code short this, problem still appears)
//this opens connection mysql server, doesn't create problems. bp = bazapodataka.getbaza(); //forming main frame.. jframe frame = new jframe(); { dimension d = toolkit.getdefaulttoolkit().getscreensize(); frame.setbounds(d.width/2 - sirina/2, d.height/2 - visina/2, sirina, visina); } frame.setdefaultcloseoperation(jframe.exit_on_close); frame.getcontentpane().setlayout(new borderlayout(0, 0)); //adding layered pane can place items inside form more 'freely' jlayeredpane layeredpane = new jlayeredpane(); frame.getcontentpane().add(layeredpane, borderlayout.center); //adding table jtable table = new jtable(); string[] rowdata = {"name:", "price:", "cathegory:", "sum:"}; defaulttablemodel model = new defaulttablemodel(rowdata, 0); jscrollpane skrol = new jscrollpane(table); table.setmodel(model); //the 2 lines below work intended resultset rs = (resultset) bp.query("select * table"); //this calls query popunitabelu(rs, model); //this populates table. table.setbounds(10, 110, 500, 350); table.setenabled(false); table.setshowhorizontallines(false); layeredpane.add(table);
populating table , displaying isn't problem, there's enough information inside table 'table' user needs scroll down.
but that's problem begins, scroll doesn't show up. how implement here. tried following solutions found on google, pretty sum on:
jscrollpane scroll = new jscrollpane(table);
which doesn't work in case.
the problem may trivial, if is, i'm sorry, i'm still learning swing. also, sorry bad english, it's not native language. :)
also, if there's forgot include, please let me know.
thank you!
you add table
2 components :
jscrollpane skrol = new jscrollpane(table);
and
layeredpane.add(table);
because of swing component can have 1 parent component second statment override first, jscrollpane
empty. seems need remove layeredpane.add(table);
as mentioned here
each gui component can contained once. if component in container , try add container, component removed first container , added second.
Comments
Post a Comment