Servus,
habe ein Problem mit einer JTextArea die sich in einem JScrollPane befindet. In die Textarea dürfen maximal 255 Zeichen rein (das funktioniert). Weiterhin soll in der Textarea autoscroll stattfinden. Und genau da liegt das Problem. Im Prinzip wird schon gescrollt. Allerdings gibts ganz am Schluss immer noch so ne Zeile wo man nurnoch gerade so den oberen Rand sehen kann. Weiter runter scrollen kann man auch nicht. Ich hab jetzt schon einiges ausprobiert aber ich bekomms einfach nicht hin. Jemand nen Tip parat?
habe ein Problem mit einer JTextArea die sich in einem JScrollPane befindet. In die Textarea dürfen maximal 255 Zeichen rein (das funktioniert). Weiterhin soll in der Textarea autoscroll stattfinden. Und genau da liegt das Problem. Im Prinzip wird schon gescrollt. Allerdings gibts ganz am Schluss immer noch so ne Zeile wo man nurnoch gerade so den oberen Rand sehen kann. Weiter runter scrollen kann man auch nicht. Ich hab jetzt schon einiges ausprobiert aber ich bekomms einfach nicht hin. Jemand nen Tip parat?
Code:
public class CommentView {
private JDialog dialog_;
private ActionListener okay_ = new CloseTheFrame();
private ActionListener cancel_ = new CloseTheFrame();
private JButton okayButton_;
private JButton cancelButton_;
private JLabel ueberschrift_;
private JTextArea comment_;
private JScrollPane scrollPane_;
private JScrollBar verticalScrollBar_;
public CommentView(JFrame frame, String title, String[] args) {
this.okayButton_ = new StandardButton("OK", okay_);
this.cancelButton_ = new StandardButton("Abbrechen", cancel_);
this.ueberschrift_ = new JLabel("Kommentar:", JLabel.LEFT);
this.ueberschrift_.setPreferredSize(new Dimension(300, 20));
this.scrollPane_ = new JScrollPane();
this.scrollPane_.setPreferredSize(new Dimension(306, 99));
this.scrollPane_.setAutoscrolls(true);
this.comment_ = new JTextArea();
this.comment_.setLineWrap(true);
this.comment_.setWrapStyleWord(true);
this.comment_.setAutoscrolls(true);
this.comment_.setDocument(new CommentDocument(255));
this.comment_.setPreferredSize(new Dimension(252, 150));
this.comment_.setText(args[1]);
this.scrollPane_.getViewport().setView(comment_);
this.verticalScrollBar_=this.scrollPane_.getVerticalScrollBar();
this.verticalScrollBar_.addAdjustmentListener(new scrollBarController());
this.dialog_ = new JDialog(frame, title, true);
this.dialog_.addWindowListener(new CloseTheFrame());
this.dialog_.setLayout(new FlowLayout());
this.dialog_.getContentPane().add(this.ueberschrift_);
this.dialog_.getContentPane().add(this.scrollPane_);
this.dialog_.getContentPane().add(this.okayButton_);
this.dialog_.getContentPane().add(this.cancelButton_);
this.dialog_.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.dialog_.setResizable(false);
this.dialog_.setPreferredSize(new Dimension(320, 200));
// JFrame soll 700px * 500 px groß sein
Dimension frameSize = new Dimension(320, 200);
// Größe des Bildschirms ermitteln
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
// Position des JFrames errechnen
int top = (screenSize.height - frameSize.height) / 2;
int left = (screenSize.width - frameSize.width) / 2;
// Größe zuordnen
this.dialog_.setSize(frameSize);
// Position zuordnen
this.dialog_.setLocation(left, top);
this.dialog_.pack();
this.dialog_.setVisible(true);
}
private class CloseTheFrame extends WindowAdapter implements ActionListener {
public void windowClosing(WindowEvent aWindowEvent) {
aWindowEvent.getWindow().dispose();
}
public void actionPerformed(ActionEvent arg0) {
dialog_.dispose();
}
}
private class scrollBarController implements AdjustmentListener{
public void adjustmentValueChanged(AdjustmentEvent e) {
if (!e.getValueIsAdjusting())
if (verticalScrollBar_.getValue() == (verticalScrollBar_.getMaximum()-verticalScrollBar_.getVisibleAmount()))
{
verticalScrollBar_.setValue(verticalScrollBar_.getMaximum() + verticalScrollBar_.getModel().getExtent());
}
}
}
}