이 코드가 도움이되기를 바랍니다. 당신은이
int len = textArea.getDocument().getLength();
textArea.setCaretPosition(len);
을해야하고 아래로 스크롤되도록 길이로, 텍스트를 wraping에 대한 실제보기를 사용 여기
textArea.setLineWrap(true);
보다는 더 많은 이해에 대한 샘플 프로그램입니다
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class CarotPosition extends JFrame
{
private JPanel panel;
private JTextArea textArea;
private JScrollPane scrollPane;
private JButton button;
public CarotPosition()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
panel = new JPanel();
panel.setLayout(new BorderLayout());
textArea = new JTextArea();
scrollPane = new JScrollPane(textArea);
textArea.setLineWrap(true);
button = new JButton("Click to add Text");
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
textArea.append("Some NEW TEXT is here...");
int len = textArea.getDocument().getLength();
textArea.setCaretPosition(len);
textArea.requestFocusInWindow();
}
});
setContentPane(panel);
panel.add(scrollPane, BorderLayout.CENTER);
panel.add(button, BorderLayout.PAGE_END);
pack();
setVisible(true);
}
public static void main(String... args)
{
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
new CarotPosition();
}
});
}
}
희망은 도움이 될 것입니다.
감사합니다.
그래서 무엇이 문제입니까? 코드를 실행하면 어떻게됩니까? –
처음에 붙어서 거기에있는 링크 된 기사를 읽은 다음 이해하지 못하는 것을 정확하게 설명하십시오. – kleopatra
'JScrollPane' 컨테이너 안에'textAreaStatus' 컴포넌트를 추가하고'setAutoscrolls (true) '로 후자를 설정하십시오 – ecle