Am besten indem du eine Klasse Schreibst die JPanel erweitert:
1 | import java.awt.FlowLayout;
|
2 | import java.awt.LayoutManager;
|
3 |
|
4 | import javax.swing.JPanel;
|
5 | import javax.swing.JTextArea;
|
6 |
|
7 |
|
8 | public class JSensorPanel extends JPanel {
|
9 | private static final long serialVersionUID = 1L;
|
10 | private JTextArea jta;
|
11 |
|
12 | //Alle Konstruktoren von JPanel Übernehmen....
|
13 | public JSensorPanel() {
|
14 | this(true);
|
15 | }
|
16 |
|
17 | public JSensorPanel(LayoutManager layout) {
|
18 | this(layout, true);
|
19 | }
|
20 |
|
21 | public JSensorPanel(boolean isDoubleBuffered) {
|
22 | this(new FlowLayout(), isDoubleBuffered);
|
23 | }
|
24 |
|
25 | public JSensorPanel(LayoutManager layout, boolean isDoubleBuffered) {
|
26 | super(layout, isDoubleBuffered);
|
27 | jta = new JTextArea();
|
28 | }
|
29 |
|
30 | /**
|
31 | * Gibt die JTextarea zurück
|
32 | * @return
|
33 | */
|
34 | public JTextArea getJTextArea() {
|
35 | return jta;
|
36 | }
|
37 | }
|
1 | private ArrayList<JSensorPanel> sensorBlatt = new ArrayList<JSensorPanel>();
|
2 | sensorBlatt.add(new JSensorPanel());
|
3 | sensorBlatt.get(0).getJTextArea().setSize(....);
|
Ansonsten hat JPanel noch eine Methode *getComponents()* da kannst du
dann mit instanceof prüfen welche davon JTextAreas sind (ist natürlich
dan ungünstig wenn es mehrere gibt!)
1 | Component[] comp = getComponents();
|
2 | for (Component component : comp) {
|
3 | if (component instanceof JTextArea) {
|
4 | JTextArea textArea = (JTextArea)component;
|
5 | textArea.setSize(400, 500);
|
6 | }
|
7 | }
|
Generell sollte man einzelne Module einer GUI nach Funktionen
untergliedern. Das muß nicht zwangsweise einen Container erweitern, aber
die größenänderung der JTextArea kannst du auch gleich in die Klasse mit
einbauen, und du wirst auch irgnewann an den Text ranwollen etc. pp.