Results 1 to 4 of 4
  1. #1
    nikolas is offline Member
    Join Date
    Jan 2015
    Posts
    11
    Rep Power
    0

    Question How to update most JList and most JTextfield with database HSQLDB ?

    Hello,

    I use Eclipse and a database HSQLDB. I try to develop in mvc.

    In my database, I have a table category (id, name) brands (id, name) product (id, product, price, description, quantity + foreign key on category and Brands).

    I started coding but I can not do that when I select one item in JList category and brand, I have to bring up the result in product (one item or multiple) and when I select one item in Jlist Product, I have to bring up the result in the JPanel Informations (price, description and quantity). I can not do this

    The IHM
    Attachment 6828

    My Code
    Java Code:
    package IHM;
    
    import javax.swing.*;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    
    import donnees.PersonneListModel;
    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);
            Container contentPane = f.getContentPane(); 
            contentPane.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);
            
            contentPane.add(jPanelProduit);
            contentPane.add(jPanelInformations);
            contentPane.add(jPanelVentes);
    
            f.setSize(700,700);
            f.pack();
            f.setVisible(true);
        }
    }
     
    class JPanelProduit extends JPanel implements ListSelectionListener {
         
        public JPanelProduit() throws SQLException {
        	JPanel panelProduit = new JPanel();
        	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());
    		listCategories.addListSelectionListener((this));
    		
    		add(new JLabel(labelMark));
    		JScrollPane listMarquesScrollPane = new JScrollPane (listMarques);        
        	add(new JScrollPane(listMarquesScrollPane));
        	listMarques.setCellRenderer(new MarquesCellRenderer());
        	listMarques.setModel(new MarquesListModel());
        	listMarques.addListSelectionListener(this);
        	
        	add(new JLabel(labelProd));
        	JScrollPane listProduitScrollPane = new JScrollPane (listProduits);        
        	add(new JScrollPane(listProduitScrollPane));
        	listProduits.addListSelectionListener(this);
    		
        }
    
    	@Override
    	public void valueChanged(ListSelectionEvent arg0) {
    		// TODO Auto-generated method stub
    		
    	}
    }
     
    class JPanelInformations extends JPanel {
      
        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.
        }
    }
    
    class JPanelVentes extends JPanel {
    	 	 
        public JPanelVentes() {
        	//JPanel PanelVentes = new JPanel(); remove the new instance of JPanel
            setLayout(new GridLayout(8,1,5,5));
            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
        }
     
    }
    Thanks,

    Nicolas

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: How to update most JList and most JTextfield with database HSQLDB ?

    Moved from SWT/JFace to AWT/Swing.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: How to update most JList and most JTextfield with database HSQLDB ?

    Quote Originally Posted by nikolas View Post
    Java Code:
    	@Override
    	public void valueChanged(ListSelectionEvent arg0) {
    		// TODO Auto-generated method stub
    		
    	}
    How to Write a List Selection Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    nikolas is offline Member
    Join Date
    Jan 2015
    Posts
    11
    Rep Power
    0

    Default Re: How to update most JList and most JTextfield with database HSQLDB ?

    Thanks for the moved to the good section.

    How to translate in java if I select an item in the JList category AND the JList Brand so I displays the result in product ? In google, I see just with one JList.

    How to translate in java if I select an item in the JList product I displays the result in JPanel JPanelInformations (3 textfield) ?

Similar Threads

  1. Replies: 3
    Last Post: 07-16-2014, 02:19 PM
  2. Trying to update a jList
    By kmccmk9 in forum AWT / Swing
    Replies: 3
    Last Post: 11-07-2013, 06:26 AM
  3. Give Focus to JTextField within JList
    By sycosquirl18 in forum AWT / Swing
    Replies: 2
    Last Post: 11-06-2011, 10:28 PM
  4. jList and jTextField
    By skidrow in forum NetBeans
    Replies: 8
    Last Post: 03-01-2011, 06:28 AM
  5. Cannot get my JList to update!
    By rangvald in forum AWT / Swing
    Replies: 1
    Last Post: 11-17-2009, 01:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •