Salut !!

Actuellement, je développe une application, et dedans il y a un JDialog.

J'ai choisi de ne pas utiliser de Layout pour organiser mes composants, cependant je suis confronté à un problème : je n'arrive pas à ajouter un scroll.

Si j'essaie d'utiliser un JScrollPane, je ne peux pas mettre le layout de ce JScrollPane à null pour agencer mes éléments comme je veux, et donc ils ne se mettent pas bien.

Comment faire ?

Voici mon code :

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
 
		title=new JLabel(getTitleString());
		Font f=title.getFont().deriveFont(Font.BOLD,30);
		title.setFont(f);
 
		title.setBounds(640/2 - getFontMetrics(f).stringWidth(getTitleString())/2 ,2,getFontMetrics(f).stringWidth(getTitleString()),35);
 
		(company=new JLabel(LanguageManager.getLocalizedText("billedCompany"))).setBounds(20,50,100,20);
		(companyField=new JFormattedTextField(NumberFormat.getNumberInstance())).setBounds(125,50,20,20);
		companyField.setEditable(false);
		(searchCompany=new JButton(LanguageManager.getLocalizedText("..."))).setBounds(150,50,20,20);
		searchCompany.addActionListener(new SearchCompany(this,true));
 
		(companyThatPays=new JLabel("payingCompany")).setBounds(20,75,100,20);;
		(companyThatPaysField=new JFormattedTextField(NumberFormat.getNumberInstance())).setBounds(125,75,20,20);
		companyThatPaysField.setEditable(false);
		(searchPayingCompany=new JButton(LanguageManager.getLocalizedText("..."))).setBounds(150,75,20,20);
		searchPayingCompany.addActionListener(new SearchCompany(this,false));
 
		(payementTerm=new JLabel(LanguageManager.getLocalizedText("payementTerm"))).setBounds(300,50,100,20);
		(payementTermField=new JTextField()).setBounds(405,50,190,20);
		payementTermField.setEditable(false);
		(searchPayement=new JButton(LanguageManager.getLocalizedText("..."))).setBounds(600,50,20,20);
		searchPayement.addActionListener(new SearchPayement(this));
 
 
		billingDate=new JLabel(LanguageManager.getLocalizedText("billingDate"));
		billingDate.setBounds(520-getFontMetrics(billingDate.getFont()).stringWidth(billingDate.getText()),75,getFontMetrics(billingDate.getFont()).stringWidth(billingDate.getText()),20);
		dateChoose=new JDateChooser(Calendar.getInstance().getTime());
		dateChoose.setLocale(LanguageManager.getCurrentLanguage());
		dateChoose.setDateFormatString(dateFormat);
		dateChoose.setBounds(520,75,100,20);
 
		payementDate=new JLabel(LanguageManager.getLocalizedText("payementDate"));
		payementDate.setBounds(520-getFontMetrics(payementDate.getFont()).stringWidth(payementDate.getText()),100,getFontMetrics(payementDate.getFont()).stringWidth(payementDate.getText()),20);
		payementDateField=new JTextField();
		payementDateField.setEditable(false);
		payementDateField.setBounds(520,100,100,20);
		(name=new JLabel(LanguageManager.getLocalizedText("companyName"))).setBounds(100,700,100,100); // 125
		quantity=new JLabel(LanguageManager.getLocalizedText("quantity"));
		unity=new JLabel(LanguageManager.getLocalizedText("unity"));
		unitPrice=new JLabel(LanguageManager.getLocalizedText("periodicityText"));
		periodicity=new JLabel(LanguageManager.getLocalizedText("unitPrice"));
		totalHT=new JLabel(LanguageManager.getLocalizedText("totalHT"));
 
		//this.setContentPane(new JScrollPane());
 
		JPanel jp=new JPanel();
		jp.setLayout(null);
 
		Container c=this.getContentPane();
 
		jp.add(title);
 
		jp.add(payementTerm);
		jp.add(payementTermField);
		jp.add(searchPayement);
 
		jp.add(company);
		jp.add(companyField);
		jp.add(searchCompany);
 
 
		jp.add(companyThatPays);
		jp.add(companyThatPaysField);
		jp.add(searchPayingCompany);
 
		jp.add(billingDate);
		jp.add(dateChoose);
 
		jp.add(payementDate);
		jp.add(payementDateField);
 
		jp.add(name);
 
		JScrollPane jsp=new JScrollPane(jp);
		this.add(jsp);
J'ai volontairement mis les bounds de name en dehors de la taille de la fenetre (700, la taille de la fenetre étant de 480).
Or c'est comme si je ne mettais pas de JScrollPane. Je ne comprends pas trop comment m'y prendre.

Merci

Fred