0
好了,所以這裏有麻煩就是含有這個問題我的代碼片段:增加的JScrollBar/JScrollPane的這個的JTextPane
private JTextField userText;
private ObjectOutputStream output;
private ObjectInputStream input;
private ServerSocket server;
private Socket connection;
private JTextPane images;
private JScrollPane jsp = new JScrollPane(images);
public Server(){
super(name+" - IM Server");
images = new JTextPane();
images.setContentType("text/html");
HTMLDocument doc = (HTMLDocument)images.getDocument();
userText = new JTextField();
userText.setEditable(false);
userText.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
sendMessage(event.getActionCommand());
userText.setText("");
}
}
);
add(userText, BorderLayout.NORTH);
add(jsp);
add(images, BorderLayout.CENTER);
images.setEditable(false);
try {
doc.insertString(0, "This is where images and text will show up.\nTo send an image, do\n*image*LOCATION OF IMAGE\n with NO SPACES or EXTRA TEXT.", null);
} catch (BadLocationException e) {
e.printStackTrace();
}
setSize(700,400);
setVisible(true);
ImageIcon logo = new javax.swing.ImageIcon(getClass().getResource("CHAT.png"));
setIconImage(logo.getImage());
}
,當我使用它,還有我的JTextPane沒有滾動條?我試過移動add(jsp);在上面和下面的位置,並將其移動到下方(圖像,BorderLayout.NORTH);灰色嗎?!所以我想知道的是如何將這個JScrollPane添加到我的JTextPane中以給它一個滾動條。提前致謝!
謝謝! @MadProgrammer – user3042719
不用擔心...;) – MadProgrammer