Bonjour,
j'ai besoin de ces deux package :
org.argil.swing.CellStyle;
org.argil.swing.XGridBag;
ou est ce que je peux les télécharger et comment faire pour les mettre de mon eclipse..
Bonjour,
j'ai besoin de ces deux package :
org.argil.swing.CellStyle;
org.argil.swing.XGridBag;
ou est ce que je peux les télécharger et comment faire pour les mettre de mon eclipse..
J'ai trouvé le code des deux classes ainsi qu'un exemple d'utilisation si ca peut t'aider :
XGridBag
CellStyle
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
79
80
81
82
83
84
85
86
87
88
89 package exemple; /* Ce code est dans le domain public */ import java.awt.Component; import java.awt.Container; import java.awt.GridBagConstraints; /** * The <code>XGridBag</code> helps to use the GridBagConstraints.<br> * This class defines styles reusable by differents components in a grid. * * To create a layout do the following step:<br> * - create a <code>GridBagLayout</code> and a XGridBag</code>.<br> * - prepare the components size (min/prefered/max).<br> * - create one or more style using <code>CellStyle.getStyle</code> method<br> * - add components to the grid using the <code>XGridBag.add</code> method.<br> * <br> * Example:<br> * <code> * GridBagLayout layout = new GridBagLayout();<br> * panel.setLayout(layout);<br> * XGridBag grid = new XGridBag(panel);<br> * <br> * CellStyle style1 = new CellStyle(1.0, 0.0,<br> * GridBagConstraints.WEST, GridBagConstraints.VERTICAL, insets, 4, 0);<br> * ...<br> * grid.add(comp1, style1, 0, 0);<br> * grid.add(comp2, style1, 0, 1);<br> * grid.add(comp3, style2, 1, 0);<br> * ..<br> * </code> * @see CellStyle * @see java.awt.GridBagConstraints * @see java.awt.Insets */ public class XGridBag extends GridBagConstraints { public Container container; /** * Add a component to the container. * The component occupy only one cell width and heigth. * * @param c component to add * @param style cell style * @param row first Y cell * @param col first X cell * @see CellStyle */ public void add(Component c, CellStyle style, int row, int col) { add(c, style, row, col, 1, 1); } /** * Add a component to the container. * * @param c component to add * @param style cell style * @param row first Y cell * @param col first X cell * @param rowHeight number of cells in a column (use GridBagConstraints.REMAINDER to fill out all rows to the end). * @param colWidth number of cells in a row (use GridBagConstraints.REMAINDER to fill out all columns to the end). * @see CellStyle */ public void add(Component c, CellStyle style, int row, int col, int rowHeight, int colWidth) { this.gridx = col; this.gridy = row; this.gridwidth = colWidth; this.gridheight = rowHeight; this.fill = style.fill; this.ipadx = style.ipadx; this.ipady = style.ipady; this.insets = style.insets; this.anchor = style.anchor; this.weightx = style.weightx; this.weighty = style.weighty; container.add(c, this); } /** * XGridBag constructor. * @param container */ public XGridBag(Container container) { super(); this.container = container; } }
Exemple d'utilisation
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
79
80
81
82 package exemple; /* Ce code est dans le domain public */ import java.awt.Insets; /** * Define a cell style used by XGridBag. * * @see XGridBag * @see java.awt.GridBagConstraints */ public class CellStyle { /** * anchor CENTER, NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST. */ int anchor; /** * fill NONE, HORIZONTAL, VERTICAL, BOTH */ int fill; /** * insets (int top, int left, int bottom, int right) */ Insets insets; /** * internal X padding */ int ipadx; /** * internal Y padding */ int ipady; /** * extra X space (none=0.0 ... all=1.0) */ double weightx; /** * extra Y space (none=0.0 ... all=1.0) */ double weighty; /** * CellStyle constructor. * * @param weightx extra X space usage (none=0.0 ... all=1.0) * @param weighty extra Y space usage (none=0.0 ... all=1.0) * @param anchor location if component doesn't occupy entire cell: * <br><code> * --------------------------------------------------<br> * |FIRST_LINE_START...PAGE_START.....FIRST_LINE_END|<br> * |LINE_START...........CENTER.............LINE_END|<br> * |LAST_LINE_START.....PAGE_END.......LAST_LINE_END|<br> * --------------------------------------------------<br> * <code> * @param fill NONE, HORIZONTAL, VERTICAL, BOTH * @param insets (int top, int left, int bottom, int right) * @param ipadx internal X padding * @param ipady internal Y padding * * @see XGridBag * @see java.awt.GridBagConstraints * @see java.awt.Insets */ public CellStyle(double weightx, double weighty, int anchor, int fill, Insets insets, int ipadx, int ipady) { super(); this.fill = fill; this.ipadx = ipadx; this.ipady = ipady; this.insets = insets; this.anchor = anchor; this.weightx = weightx; this.weighty = weighty; } }
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160 package exemple; /* Ce code est dans le domain public */ import java.awt.Dimension; import java.awt.EventQueue; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSpinner; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.ScrollPaneConstants; import javax.swing.UIManager; import javax.swing.border.EmptyBorder; import org.argil.swing.CellStyle; import org.argil.swing.XGridBag; public class DemoGridBag { public static void main(String[] args) throws Exception { EventQueue.invokeLater(new Runnable() { public void run() { try { UIManager.setLookAndFeel(UIManager .getSystemLookAndFeelClassName()); } catch (Exception e) { throw new RuntimeException(e); } DemoGridBag demo = new DemoGridBag(); JFrame frame = new JFrame("Formulaire"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); demo.createLayout(frame); frame.setLocationByPlatform(true); frame.pack(); frame.setVisible(true); } }); } JLabel lbhPresentation = new JLabel( "<html><b>Demande d'inscription au stage de fin d'étude:</b>" + "<dl><dd>Remplir ce formulaire avant le 10 mai." + " Préciser la zone géographique."); JLabel lbhSujet = new JLabel("Sujet du stage:"); JLabel lbNom = new JLabel("Nom:"); JLabel lbPrenom = new JLabel("Prénom:"); JLabel lbAge = new JLabel("Age:"); JTextField tfSujet = new JTextField(""); JSpinner spinnerAge = new JSpinner(); JComboBox boxSexe = new JComboBox(new Object[] { "Masculin", "Féminin" }); JLabel lbSexe = new JLabel("Sexe:"); JTextField tfNom = new JTextField("Dupond"); JTextField tfPrenom = new JTextField("Pierre"); JTextArea txtSujet = new JTextArea( "Réaliser un logiciel graphique de calcul de contraintes mécaniques en langage Java.\n" + "De préférence au sud ouest de Paris."); JScrollPane txtPane = new JScrollPane(txtSujet, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); private void createLayout(JFrame frame) { // Créer le layout JPanel panel = (JPanel) frame.getContentPane(); panel.setBorder(new EmptyBorder(6, 6, 6, 6)); GridBagLayout layout = new GridBagLayout(); panel.setLayout(layout); // Créer les inserts (insets) Insets cellInsets = new Insets(2, 2, 2, 2); Insets cellInsets2 = new Insets(2, 12, 2, 2); // Préparer les composants Dimension dimSpinner = spinnerAge.getPreferredSize(); Dimension dimBox = boxSexe.getPreferredSize(); int maxH = Math.max(dimSpinner.height, dimBox.height); setHeigth(spinnerAge, maxH); setWidth(spinnerAge, 40); setHeigth(boxSexe, maxH); setWidth(boxSexe, 80); txtSujet.setRows(3); txtSujet.setLineWrap(true); txtSujet.setWrapStyleWord(true); // Créer les styles de cellule CellStyle titleStyle = new CellStyle(0.0, 0.0, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, new Insets(12, 2, 2, 2), 2, 0); CellStyle fixStyle = new CellStyle(0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, cellInsets, 2, 4); CellStyle fixStyle2 = new CellStyle(0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.NONE, cellInsets2, 2, 4); CellStyle varHStyle = new CellStyle(0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, cellInsets, 2, 0); CellStyle varHVStyle = new CellStyle(1.0, 1.0, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.BOTH, cellInsets, 2, 0); // Ajouter les composants XGridBag g = new XGridBag(panel); // Row 0 g.add(lbhPresentation, titleStyle, 0, 0, 1, 5); // Row 1 g.add(lbNom, fixStyle, 1, 0); g.add(tfNom, varHStyle, 1, 1, 1, 4); // Row 2 g.add(lbPrenom, fixStyle, 2, 0); g.add(tfPrenom, varHStyle, 2, 1, 1, 4); // Row 3 g.add(lbAge, fixStyle, 3, 0); g.add(spinnerAge, fixStyle, 3, 1); g.add(lbSexe, fixStyle2, 3, 2); g.add(boxSexe, fixStyle, 3, 3); // Row 4 g.add(lbhSujet, titleStyle, 4, 0, 1, 5); // Row 5 g.add(txtPane, varHVStyle, 5, 0, 1, 5); } private static void setHeigth(JComponent c, int h) { Dimension dim = c.getPreferredSize(); dim.height = h; c.setPreferredSize(dim); c.setMinimumSize(dim); c.setMaximumSize(dim); } private static void setWidth(JComponent c, int w) { Dimension dim = c.getPreferredSize(); System.out.println(dim); dim.width = w; c.setPreferredSize(dim); c.setMinimumSize(dim); c.setMaximumSize(dim); } }
dans quel projet je dois creer ces classes?
ou bien je déclare simple classe avec ce code?
Partager