Правильный способ сделать это - создать собственный вид, который при необходимости рисует многоточие. Но так как я понятия не имею, как это сделать, я попробую небольшой хак, который вы можете использовать:
// This comment is here so that the text will wrap to the next line and you should see the ellipsis,
// indicating that there is more text.
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.text.*;
class TextAreaEllipsis
{
public static void main(String a[])
{
JTextArea textArea = new JTextArea(4, 15)
{
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
int preferredHeight = (int)getUI().getRootView(this).getPreferredSpan(View.Y_AXIS);
if (preferredHeight > getSize().height)
paintEllipsis(g);
}
private void paintEllipsis(Graphics g)
{
try
{
int caretWidth = 1;
FontMetrics fm = getFontMetrics( getFont() );
String ellipsis = "...";
int ellipsisWidth = fm.stringWidth( ellipsis ) + caretWidth;
Insets insets = getInsets();
int lineWidth = getSize().width - insets.right;
Point p = new Point(lineWidth, getSize().height - 1);
int end = viewToModel( p );
Rectangle endRectangle = modelToView( end );
int start = end;
Rectangle startRectangle = endRectangle;
int maxWidth = lineWidth - ellipsisWidth;
while (startRectangle.x + startRectangle.width > maxWidth)
{
startRectangle = modelToView( --start );
}
Rectangle union = startRectangle.union( endRectangle );
g.setColor( getBackground() );
g.fillRect(union.x + caretWidth, union.y, union.width, union.height);
g.setColor( getForeground() );
g.drawString("...", union.x + caretWidth, union.y + union.height - fm.getDescent());
}
catch(BadLocationException ble)
{
System.out.println( ble );
}
}
};
textArea.setLineWrap( true );
textArea.setWrapStyleWord( true );
textArea.setPreferredSize( textArea.getPreferredScrollableViewportSize() );
try
{
FileReader reader = new FileReader( "TextAreaEllipsis.java" );
BufferedReader br = new BufferedReader(reader);
textArea.read( br, null );
br.close();
}
catch(Exception e2) { System.out.println(e2); }
JFrame frame = new JFrame("TextArea Ellipsis");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(textArea);
frame.pack();
frame.setLocationRelativeTo( null );
frame.setVisible(true);
}
}