bonjour,
j'ai une classe TabbedStore (qui hérite de JTabbedPane) qui se compose de 2 objets de la classe StoreTable (qui hérite de JTable).
mon problème est le suivant:
je n'arrive pas à associer un scroll pane aux 2 tables qui composent mon tabbed pane.
je vous associe le code pour que vous puissez l'executer chez vous:
TabbedStore.java
StoreTable.java
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 import java.awt.Dimension; import java.awt.event.KeyEvent; import javax.swing.JScrollPane; import javax.swing.JTabbedPane; public class TabbedStore extends JTabbedPane { // ------------------------------------------------------------------------ // Elements declaration of the Store Component // ------------------------------------------------------------------------ private StoreTable personnalTable; private StoreTable otherPersonsTable; public TabbedStore(Language lang, Object[][] data1, Object[][] data2) { super(); personnalTable = new StoreTable(lang, data1); personnalTable.setPreferredSize(new Dimension(400, 110)); //Create the scroll pane and add the table to it. JScrollPane scrollPane1 = new JScrollPane(personnalTable); //là est le problème //Add the scroll pane to this panel. add(scrollPane1); otherPersonsTable = new StoreTable(lang, data2); otherPersonsTable.setPreferredSize(new Dimension(400, 110)); //Create the scroll pane and add the table to it. JScrollPane scrollPane2 = new JScrollPane(otherPersonsTable);//là est le problème //Add the scroll pane to this panel. add(scrollPane2); String[] titles = lang.getCertifStoreTitle(); this.addTab(titles[0], personnalTable); this.setMnemonicAt(0, KeyEvent.VK_1); this.addTab(titles[1], otherPersonsTable); this.setMnemonicAt(1, KeyEvent.VK_2); } }
Language.java
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 import java.awt.Dimension; import javax.swing.JTable; import MainInterface.observant.Observant; public class StoreTable extends JTable{ // ------------------------------------------------------------------------ // Elements declaration of the Store Component // ------------------------------------------------------------------------ // objects to put in the table private Object[][] data; public StoreTable(Language lang, Object[][] data){ super(data, lang.getTableHeaders()); super.setPreferredScrollableViewportSize(new Dimension(400, 110)); this.data = data; } }
et voici la classe de test qui appelle tout ça:
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 public class Language { private String language; public Language(String language) { this.language = language; } public String[] getTableHeaders(){ String[] th = new String[3]; if(language.equalsIgnoreCase("french")){ th[0] = "Délivré à"; th[1] = "Délivré par"; th[2] = "Date d'expiration"; }else{ if(language.equalsIgnoreCase("english")){ th[0] = "Delivred in"; th[1] = "Delivred by"; th[2] = "Scratch date"; } } return th; } public String[] getCertifStoreTitle(){ String[] th = new String[2]; if(language.equalsIgnoreCase("french")){ th[0] = "Personnel"; th[1] = "Autres personnes"; }else{ if(language.equalsIgnoreCase("english")){ th[0] = "Personnal"; th[1] = "Other persons"; } } return th; } public String getButtonOKTitle(){ return "OK"; } public String getButtonCancelTitle(){ if(language.equalsIgnoreCase("french")){ return "Annuler"; }else{ if(language.equalsIgnoreCase("english")){ return "Cancel"; } } return null; } }
InterfaceTest2.java
voilà s'il manque un truc signalez le moi car mon projet contient beaucoup plus que ça et j'ai arraché ces classes sans vérifier si elles fonctionnent toutes seules.
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
78 import java.awt.BorderLayout; import java.awt.GridLayout; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; public class InterfaceTest2 extends JPanel { private boolean DEBUG = false; public InterfaceTest2() { super(new GridLayout(1,1)); Object[][] data = { {"Mary", "Campione", "Snowboarding"}, {"Alison", "Huml", "Rowing"}, {"Kathy", "Walrath", "Knitting"}, {"Sharon", "Zakhour", "Speed reading"}, {"Philip", "Milne", "Pool"} }; Language lang = new Language("french"); TabbedStore tabbedPane = new TabbedStore(lang, data, data); //add the tabbed store add(tabbedPane); } protected JComponent makeTextPanel(String text) { JPanel panel = new JPanel(false); JLabel filler = new JLabel(text); filler.setHorizontalAlignment(JLabel.CENTER); panel.setLayout(new GridLayout(1, 1)); panel.add(filler); return panel; } /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. */ private static void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame("TabbedStoreDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. JComponent newContentPane = new InterfaceTest2(); newContentPane.setOpaque(true); //content panes must be opaque frame.getContentPane().add(new InterfaceTest2(), BorderLayout.CENTER); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }
en plus il y a un autre problème: il me crée 4 onglets alors que je n'ai demandé que 2.
merci d'avance







Répondre avec citation


Partager