java - 3 Jpanel in JFrame, my button is not visible -
i have jframe
3 jpanel
objects. have problem 2 of panels. can see in frame, panel jpanelproduit
object panel, jpanelinformations
, jpanelventes
, see nothing. error?
my code
package ihm; import javax.swing.*; import donnees.categories; import donnees.categoriescellrenderer; import donnees.categorieslistmodel; import donnees.marques; import donnees.marquescellrenderer; import donnees.marqueslistmodel; import donnees.produits; import donnees.produitscellrenderer; import donnees.produitslistmodel; import fabriques.fabcategories; import fabriques.fabmarques; import java.awt.*; import java.sql.connection; import java.sql.drivermanager; import java.sql.sqlexception; public class fenetre { static connection conn; public static void main(string[] args) throws classnotfoundexception, sqlexception { class.forname("org.hsqldb.jdbcdriver"); conn=drivermanager.getconnection("jdbc:hsqldb:file:bdd/bdd","sa",""); fabcategories.getinstance().demarrerconnexion(conn); fabmarques.getinstance().demarrerconnexion(conn); jframe f = new jframe("gestion des produits"); f.setdefaultcloseoperation(windowconstants.exit_on_close); f.setlayout(new gridlayout(1,2,3, 3)); jpanelproduit jpanelproduit = new jpanelproduit(); jpanelinformations jpanelinformations = new jpanelinformations(); jpanelventes jpanelventes = new jpanelventes(); jpanelproduit.setbackground(color.green); jpanelproduit.setbackground(color.yellow); jpanelventes.setbackground(color.pink); f.add(jpanelproduit); f.add(jpanelinformations); f.add(jpanelventes); f.setsize(700,700); f.pack(); f.setvisible(true); } } class jpanelproduit extends jpanel { public jpanelproduit() throws sqlexception { setlayout(new gridlayout(5,2,5,5)); string labelcat = "categories"; string labelmark = "marques"; string labelprod = "produits"; jlist<categories> listcategories= new jlist<categories> (); jlist<marques> listmarques= new jlist<marques> (); jlist<produits> listproduits= new jlist<produits> (); jscrollpane listcategoriesscrollpane = new jscrollpane (listcategories); add(new jlabel(labelcat)); add(new jscrollpane(listcategoriesscrollpane)); listcategories.setcellrenderer(new categoriescellrenderer());; listcategories.setmodel(new categorieslistmodel()); add(new jlabel(labelmark)); jscrollpane listmarquesscrollpane = new jscrollpane (listmarques); add(new jscrollpane(listmarquesscrollpane)); listmarques.setcellrenderer(new marquescellrenderer()); listmarques.setmodel(new marqueslistmodel()); add(new jlabel(labelprod)); jscrollpane listproduitscrollpane = new jscrollpane (listproduits); add(new jscrollpane(listproduitscrollpane)); //listproduits.setcellrenderer(new produitscellrenderer()); //listproduits.setmodel(new produitslistmodel()); } } class jpanelinformations extends jpanel { public jpanelinformations() { jpanel panelinformation = new jpanel(); setlayout(new gridlayout(7,1,5,5)); jlabel labelinfo = new jlabel ("information"); jlabel labelprix = new jlabel ("prix"); jlabel labeldesc = new jlabel ("description"); jlabel labelquant = new jlabel ("quantite"); jtextfield fieldprix = new jtextfield (20); jtextarea fielddesc = new jtextarea (20, 20); jtextfield fieldquantite = new jtextfield (20); panelinformation.add(labelinfo); panelinformation.add(labelprix); panelinformation.add(fieldprix); panelinformation.add(labeldesc); panelinformation.add(fielddesc); panelinformation.add(labelquant); panelinformation.add(fieldquantite); } } class jpanelventes extends jpanel { public jpanelventes() { jpanel panelventes = new jpanel(); setlayout(new gridlayout()); jlabel labelvendre = new jlabel ("vendre"); jlabel labelqte = new jlabel ("quantite"); jlabel labelpromo = new jlabel ("promotion"); jlabel labeltot = new jlabel ("total"); jtextfield fieldqte = new jtextfield (20); jtextfield fieldpromoeuros = new jtextfield (20); jtextfield fieldpromopourcent = new jtextfield (20); jtextfield fieldtotal = new jtextfield (20); panelventes.add (labelvendre); panelventes.add (labelqte); panelventes.add (fieldqte); panelventes.add (labelpromo); panelventes.add (fieldpromoeuros); panelventes.add (fieldpromopourcent); panelventes.add (labeltot); panelventes.add (fieldtotal); } }
try out this:
public jpanelinformations() { //jpanel panelinformation = new jpanel(); remove new instance of panel setlayout(new gridlayout(7,1,5,5)); jlabel labelinfo = new jlabel ("information"); jlabel labelprix = new jlabel ("prix"); jlabel labeldesc = new jlabel ("description"); jlabel labelquant = new jlabel ("quantite"); jtextfield fieldprix = new jtextfield (20); jtextarea fielddesc = new jtextarea (20, 20); jtextfield fieldquantite = new jtextfield (20); add(labelinfo); //remove panelinformation. add(labelprix);//remove panelinformation. add(fieldprix);//remove panelinformation. add(labeldesc);//remove panelinformation. add(fielddesc);//remove panelinformation. add(labelquant);//remove panelinformation. add(fieldquantite);//remove panelinformation. }
and
public jpanelventes() { //jpanel panelventes = new jpanel(); remove new instance of jpanel setlayout(new gridlayout()); jlabel labelvendre = new jlabel ("vendre"); jlabel labelqte = new jlabel ("quantite"); jlabel labelpromo = new jlabel ("promotion"); jlabel labeltot = new jlabel ("total"); jtextfield fieldqte = new jtextfield (20); jtextfield fieldpromoeuros = new jtextfield (20); jtextfield fieldpromopourcent = new jtextfield (20); jtextfield fieldtotal = new jtextfield (20); add (labelvendre); //remove panelventes add (labelqte);//remove panelventes add (fieldqte);//remove panelventes add (labelpromo);//remove panelventes add (fieldpromoeuros);//remove panelventes add (fieldpromopourcent);//remove panelventes add (labeltot);//remove panelventes add (fieldtotal);//remove panelventes }
Comments
Post a Comment