[Java] JTextarea scrollt nicht

Hallo!

Ich möchte gerne eine horizontal scrollende JTextArea.

JTextArea txtLogging = new JTextArea();
JScrollPane scpLogging = new JScrollPane(txtLogging);

// Horizontales Scrolling bei Bedarf aktivieren
scpLogging.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scpLogging.setAutoscrolls(true);

// Komponenten dem Panel hinzufügen
pnlJDBCTest.add(txtLogging, new GridBagConstraints(1, 2, 2, 2, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new
Insets(0, 39, 0, 43), 284, 114));
pnlJDBCTest.add(scpLogging, new GridBagConstraints(1, 2, 2, 2, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new
Insets(0, 39, 0, 43), 284, 114));

Auch wenn ich die gesamte TextArea vollschreibe erscheint keine
Scrollbar. Was mache ich falsch?

Grüße, Tanja

Hallo Tanja,

mit scpLogging.getViewport();

sollte es vielleicht gehen.

m.f.g.

Thomas

[Bei dieser Antwort wurde das Vollzitat nachträglich automatisiert entfernt]

Lösung

Hallo Thomas!

mit scpLogging.getViewport();

sollte es vielleicht gehen.

Danke, aber ich habe den Fehler in der Zwischenzeit selbst gefunden. Es funktioniert, wenn ich

pnlJDBCTest.add(txtLogging, new GridBagConstraints(1, 2, 2, 2, 1.0, 1.0
,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 39, 0, 43), 284, 114));

weglasse, denn ich muß die JTextArea txtLogging ja gar nicht mehr auf mein Panel pnlJDBCTest adden, da ich sie bereits dem JScrollPane hinzugefügt habe, was wiederum eine Art Panel darstellt. Somit reicht es, wenn das JScrollPane zu pnlJDBCTest hinzugefügt wird.

Grüße, Tanja