Java JTextArea没有';I don’我没把所有的字都说出来
我有一个叫杰帕内尔的人。我在里面放了4个组件,3个jlabel和1个JTextArea。最后一行是JTextArea组件。此GridegabLayout面板添加到另一个JPanelfor。JTextArea中的文本存在以下问题:Java JTextArea没有';I don’我没把所有的字都说出来,java,swing,jtextarea,Java,Swing,Jtextarea,我有一个叫杰帕内尔的人。我在里面放了4个组件,3个jlabel和1个JTextArea。最后一行是JTextArea组件。此GridegabLayout面板添加到另一个JPanelfor。JTextArea中的文本存在以下问题: 1. Text in JTextArea cannot show it all. 2. If there are too many word, the first two row of labels cannot see. 在图片的右侧,我将文本改为许多单词。前两
1. Text in JTextArea cannot show it all.
2. If there are too many word, the first two row of labels cannot see.
在图片的右侧,我将文本改为许多单词。前两排已经不见了
下面是我的GridgeabLayout JPanel代码:
包装PDFAnnotationPackage
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTextPane;
public class DivCommentJPane extends JPanel {
private BeanPanel thisBean;
private CommentItem thisComment;
private String pageErrorPrefix="Error On DivCommentJPane.java : ";
private PDFNotes bean;
private GridBagConstraints c;
public DivCommentJPane(CommentItem comment ,BeanPanel bean ){
//thisBean=bean;
super();
thisComment=comment;
thisBean=test;
setting();
}
public void setting(){
try{
bean=new PDFNotesBean();
this.setLayout( new GridBagLayout());
c = new GridBagConstraints();
c.anchor = GridBagConstraints.WEST;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1.0; // **** comment this line out to see effect ****
c.weighty = 1.0; // **** comment this line out to see effect ****
buildTopJPane();
setVisible(true);
}catch(Exception err){
Utility.DisplayErrorMsg(pageErrorPrefix+ err.getMessage().toString());
}
}
private JLabel setAttonIconCreator(){
Icon icon=getAnotIcon();
JLabel lblAnottIcon=new JLabel(thisComment.creator, icon, JLabel.CENTER);
return lblAnottIcon;
}
private JLabel setDeleteIcon(){
ImageIcon icon = new ImageIcon(getClass().getResource("Delete.gif"));
JLabel lblDeleteIcon=new JLabel("", icon, JLabel.CENTER);
lblDeleteIcon.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
thisBean.annotRemove(thisComment.annotation, thisComment.pageNum);
}
});
return lblDeleteIcon;
}
private JLabel setPageDateLabel(){
JLabel lblDate=new JLabel(thisComment.toString());
return lblDate;
}
/*private JTextPane setContent(){
JTextPane pane = new JTextPane();
pane.setText(thisComment.content);
pane.setEditable(false);
return pane;
}*/
/*private JTextArea setContent(){
JTextArea t=new JTextArea();
t.setText(thisComment.content);
t.setLineWrap(true);
t.setEditable(false);
return t;
}*/
//modified the code like to use JScrollPane
private JScrollPane setContent(){
JScrollPane scroll=new JScrollPane();
scroll.setPreferredSize(new Dimension(250, 250));
JTextArea t=new JTextArea(3,120);
t.setText(thisComment.content);
t.setLineWrap(true);
t.setEditable(false);
scroll.getViewport().add(t);
return scroll;
}
private void buildTopJPane(){
JPanel lnFirst=new JPanel();
try{
c.gridx = 0;
c.gridy = 0;
c.fill = GridBagConstraints.NONE;
this.add(setAttonIconCreator(), c);
c.gridx = 5;
c.gridy = 0;
this.add(setDeleteIcon(),c);
c.gridx=0;
c.gridy=1;
c.gridwidth=4;
this.add(setPageDateLabel(), c);
c.gridx=0;
c.gridy=2;
c.gridwidth=4;
this.add(setContent(), c);
} catch(Exception err){
Utility.DisplayErrorMsg(pageErrorPrefix+ err.getMessage().toString());
}
}
@SuppressWarnings("finally")
private SafeIcon getAnotIcon(){
SafeIcon antIcon=null;
try{
switch (thisComment.type.toLowerCase()){
case "underline":
antIcon= new SafeIcon( bean.getAnnotToolbar().getjbTextUnderline().getIcon());
break;
case "squiggly":
antIcon=new SafeIcon(bean.getjbTextSquiggly().getIcon());
break;
case "highlight":
antIcon=new SafeIcon(bean.getjbHighlight().getIcon());
break;
case "note":
antIcon=new SafeIcon(bean.getAnnotToolbar().getjbNote().getIcon());
default:
antIcon=new SafeIcon((Icon) ImageIO.read(getClass().getResource("SquigglyIcon.gif")));
return antIcon;
}
}catch(IOException err){
Utility.DisplayErrorMsg(pageErrorPrefix+ err.getMessage().toString());
}finally{return antIcon;}
}
}
这是在JScrollPane中添加JTextArea后的屏幕截图
考虑将
JTextArea
添加到JScrollPane
中,并使用newjtextarea(3120)
创建JTextArea,为指定行/列的文本区域指定一个首选大小。@camickr,我不知道要显示的总字数。这是从其他来源,我不能限制多少字的用户可以input@user819774,也就是说,需要时将显示滚动条。我们的想法是为文本区域提供一个默认大小,这样可以在不使文本区域过大的情况下合理地处理大部分文本。但JtextArea仅显示带有滚动条的1个字符。私有JScrollPane setContent(){JScrollPane scroll=new JScrollPane();JTextArea t=new JTextArea(3120);t.setText(thiscompent.content);t.setLineWrap(true);t.setEditable(false);scroll.getViewport().add(t);return scroll;}