Bonsoir
J'ai essayer d'utiliser un JScrollPane pour afficher une liste d'items recouvrés d'Amazon avec la bibliothèque Jsoup mais ça ne marche pas
Voici Mon code
La classe main
La classe ProduitPanel qui herite du JPanel est contient les info du produits
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 public javax.swing.JPanel mainPanel; public class Frame extends javax.swing.JFrame { public javax.swing.JPanel mainPanel; /** * Creates new form Frame */ int x=10 , y=10; ProduitPanel Prodpan; ParserAmazon t = new ParserAmazon(); public Frame() throws IOException { initComponents(); for(int i=0;i<t.produit.size();i++){ Prodpan = new ProduitPanel(x, y); Prodpan.img.setText("<html><body><<img src=\""+t.produit.elementAt(i).img+"\" width=\""+Prodpan.img.getWidth()+"\" height=\""+Prodpan.img.getHeight()+"\"></body></html>"); Prodpan.prix.setText(Double.toString(ParserAmazon.produit.elementAt(i).price)+"$"); Prodpan.setName("Product :" + Integer.toString(i)); Prodpan.title.setText("<html><body><<a href=\""+t.produit.elementAt(i).url+"\">"+"<h2>"+t.produit.elementAt(i).title+"</h2></a></body></html>"); mainPanel.add(Prodpan); y+=Prodpan.getHeight()+10; } JScrollPane js = new javax.swing.JScrollPane(mainPanel); this.add(js); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 import java.awt.Font; import java.util.Vector; import javax.swing.*; public class ProduitPanel extends JPanel { JLabel img,title,prix; public ProduitPanel(int i,int j){ super(); this.setBounds(i, j , 800,250); img = new JLabel("IMAGE"); title = new JLabel("TITLE"); prix = new JLabel("PRIX"); img.setBounds(10, 20, 150,200); title.setBounds(170, 20, 600 , 80); prix.setBounds(170, 120, 400, 50); this.add(img); this.add(title); this.add(prix); this.setBorder(BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); this.setLayout(null); this.setVisible(true); } }
Partager