package ChatExtends;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.Border;
public class ChatWindow extends JFrame{
public String username;
public void load() throws Exception{
this.setSize(1000,800);
this.setName("ChatWindow");
this.setResizable(false);
Container ct = this.getContentPane();
File mimage = new File("images/mlogo.png");
Image mainimage = ImageIO.read(mimage);
this.setIconImage(mainimage);
JPanel buttom = new JPanel();
buttom.setSize(1000,100);
buttom.setLayout(new BorderLayout());
JTextArea inputtext = new JTextArea(1,80);
JTextArea MessageArea = new JTextArea();
inputtext.setLineWrap(true);
inputtext.setWrapStyleWord(true);
inputtext.setTabSize(2);
inputtext.setPreferredSize(new Dimension(700,100));
//inputtext.setFont(new Font("Arial",Font.BOLD,15));
Border b = BorderFactory.createLineBorder(Color.BLACK);
inputtext.setBorder(b);
inputtext.setTabSize(2);
inputtext.setFont(new Font("Arial",Font.BOLD,20));
buttom.add(inputtext,BorderLayout.WEST);
JButton SendButton = new JButton("Send");
//SendButton.setPreferredSize(new Dimension(1000-inputtext.WIDTH,100));
Font S = new Font("Arail",Font.ITALIC,50);
SendButton.setFont(S);
SendButton.setFocusable(false);
SendButton.setBorder(b);
SendButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//throw new UnsupportedOperationException("Unimplemented method 'actionPerformed'");
String out = inputtext.getText().trim();
MessageArea.append(out);
MessageArea.paintImmediately(MessageArea.getBounds());
inputtext.setText("");
}
});
buttom.add(SendButton,BorderLayout.EAST);
ct.add(buttom,"South");
JPanel Top = new JPanel();
JLabel name = new JLabel(username);
name.setHorizontalAlignment(SwingConstants.CENTER);
name.setVerticalAlignment(SwingConstants.CENTER);
Font t = new Font("Arial",Font.ITALIC,50);
name.setFont(t);
Top.add(name);
ct.add(Top,"North");
JPanel Center = new JPanel();
MessageArea.setEditable(false);
MessageArea.setBounds(0,300,1000,700);
MessageArea.setPreferredSize(new Dimension(1000,500));
MessageArea.setBackground(Color.white);
MessageArea.setForeground(Color.black);
MessageArea.setFocusable(false);
Center.add(MessageArea);
ct.add(Center,"Center");
this.setVisible(true);
}
}
请问能不能在放大字体的时候不让JTextArea的大小自动放大?