JTextArea: scrollbar never appearing
Hi all,
I have a little problem with a JTextArea. I created a scrollbar, but this will never appear! Instead the whole window increases in size, and other objects disappear :-(
What can i do?
Thanks guys!
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*; // Needed for ActionListener
////////////////////////////////////////////////////////class DogYears2
class DogYears3 extends JFrame {
//======================================================== constants
//=============================================== instance variables
//protected RemoteController rc;
private JTextField _CmdString= new JTextField(20);
private JTextArea _ResponseFeed = new JTextArea(10, 50);
String[] CmdStringArray = new String[100];
//====================================================== constructor
public DogYears3() {
//1... Create/initialize components
JButton sendButton = new JButton("Send");
sendButton.addActionListener(new SendButtonListener());
_CmdString.addActionListener(new SendButtonListener());
_CmdString.setText("052014009f9d");
_ResponseFeed.setEditable(false);
_ResponseFeed.setLineWrap(true);
JScrollPane scroller = new JScrollPane(_ResponseFeed);
//scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
//rc = new RemoteController();
// 2... Create content panel, set layout
JPanel content = new JPanel();
content.setLayout(new FlowLayout());
// 3... Add the components to the content panel.
content.add(new JLabel("Enter Command"));
content.add(_CmdString);
content.add(sendButton);
content.add(scroller);
content.add(_ResponseFeed);
// 4... Set this window's attributes, and pack it.
setContentPane(content);
pack();// Layout components.
setTitle("Skyetek M1mini control panel");
//setSize(700, 300);
//validate();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null); // Center window.
}
////////////////////////////////////////////////// SendButtonListener
class SendButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
GetCommand();
}
}
// class ReponseListener{
public void ResponseReceived(String Rsp) {
FeedResponse(Rsp);
System.out.println("Received message");
}
// }
//====================================================== my methods
public void FeedResponse(String Rsp){
try{
_ResponseFeed.append("rg" +"\n" +Rsp +"\n");
}catch (Exception ex)
{
System.out.println(ex);
}
}
public void GetCommand(){
try{
String b1 = _CmdString.getText();
int NumOfBytes = (b1.length())/2;
int[] HEX = new int[NumOfBytes];
short[] Cmd = new short[NumOfBytes];
//System.out.println("NumOfBytes" +NumOfBytes);
for (int k = 0; k<NumOfBytes;++k){
CmdStringArray[k] = b1.substring(2*k,(2*k)+2);
//System.out.println("CmdStringArray position" +k );
//System.out.println("CmdStringArray=" +CmdStringArray[k]);
HEX[k] = Integer.parseInt(CmdStringArray[k].trim(), 16 /* radix */);
Cmd[k] = (short)HEX[k];
//System.out.println("Cmd position" +k );
//System.out.println("Cmd=" +Cmd[k]);
}
ResponseReceived("igiugigrgas grasdashgds hfyxdfhgaehdfh waehgfwaeshdshdashigizgi igiugigrgas grasdashgds hfyxdfhgaehdfh waehgfwaeshdshdashigizgi igiugigrgas grasdashgds hfyxdfhgaehdfh waehgfwaeshdshdashigizgi");
// rc.sendCommand(Cmd);
} catch (Exception ex)
{
System.out.println(ex);
}
}
//====================================================== method main
public static void main(String[] args) {
DogYears3 window = new DogYears3();
window.setVisible(true);
}
}>

