java - JTable nicely sized in JPanel -
i had problem java's form. tried size jtable take entire space on jpanel, won't. have advice me ? show problem , code, of you.
and code here
package displayinglibrary; import java.awt.borderlayout; import java.awt.color; import java.awt.dimension; import java.util.arraylist; import javax.swing.jbutton; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.jscrollpane; import javax.swing.jtable; import javax.swing.table.defaulttablemodel; import com.sdz.connection.sdzconnection; import librarydao.dao; import librarytable.ouvrage; import librarytabledao.ouvragedao; public class displaylibrary extends jframe{ public displaylibrary() { this.setlocationrelativeto(null); this.setdefaultcloseoperation(jframe.exit_on_close); this.settitle("jtable"); this.setsize(1000, 600); this.setbounds(100, 100, 941, 495); this.getcontentpane().setlayout(null); jpanel panel = new jpanel(); panel.setbounds(10, 11, 712, 434); this.getcontentpane().add(panel); panel.setbackground(color.orange); jtable table = new jtable(); jscrollpane tablesp = new jscrollpane(table); panel.add(tablesp); defaulttablemodel model = new defaulttablemodel(); object[] columnsname = new object[4]; columnsname[0] = "id"; columnsname[1] = "code ouvrage"; columnsname[2] = "nom ouvrage"; columnsname[3] = "nom auteur"; model.setcolumnidentifiers(columnsname); object[] rowdata = new object[4]; dao<ouvrage> ouvragedao = new ouvragedao(sdzconnection.getinstance()); arraylist<ouvrage> ouvrages = ouvragedao.getlist(); for(int = 0; < ouvragedao.getlist().size(); i++) { rowdata[0] = ouvrages.get(i).getid_ouvrage(); rowdata[1] = ouvrages.get(i).getcode_ouvrage(); rowdata[2] = ouvrages.get(i).getnom_ouvrage(); rowdata[3] = ouvrages.get(i).getnom_auteur(); model.addrow(rowdata); } table.setmodel(model); //this.getcontentpane().add(new jscrollpane(table)); } public static void main(string[] args){ displaylibrary dl = new displaylibrary(); dl.setvisible(true); } }
i color panel orange show problem, have hide color. had add borderlayout, or when want had setlayout(null) jpanel resize jtable, jtable dissapear. again help.
edit of camickr
with following code
this.setlocationrelativeto(null); this.setdefaultcloseoperation(jframe.exit_on_close); this.settitle("jtable"); this.setsize(1000, 600); this.setbounds(100, 100, 941, 495); /*jpanel panel = new jpanel(); panel.setbounds(10, 11, 712, 434); this.getcontentpane().add(panel); panel.setbackground(color.orange);*/ jtable table = new jtable(); table.setsize(700, 400); jscrollpane tablesp = new jscrollpane(table); borderlayout borlay = new borderlayout(); //panel.add(tablesp); this.getcontentpane().add(tablesp, borlay.center); jbutton button = new jbutton(); button.setsize(40, 40); this.getcontentpane().add(button, borlay.line_end); jbutton button_2 = new jbutton(); this.getcontentpane().add(button_2, borlay.line_end);
the problem jtable take place in contentpane, that's why made jpanel have 1 side (about 75% of window) , other panel have button , combobox.
so add table center
, panel line_end
area of borderlayout
.
read section swing tutorial on how use borderlayout more information , working examples.
Comments
Post a Comment