How to implement a JTextArea that emulates the console (messages)?
843829Feb 16 2006 — edited Feb 23 2006Hi everyone,
here is my problem, for the moment in my opinion enormous.
I am creating an application and one of its parts should be a Text Area whish shows (only read-only) the messages as the console(MSDOs or the one of eclipse, that is the one i�m using) does.
I am using eclipse and it has a console (as teh commad in MSDOS or the terminal in linux) and all the messages showed there have to be seen in the mentioned TextArea. I do not really know how to implement and how to use if it is neccesary (I really doubt it) the listener.
If anyone could help me, it would be great.
Tanks.
The code done for the moment for this part is reallys obvious:
//Build the menu bar of the main application
public JComponent createConsole() {
//group the buttons in a panel to be together
JPanel panelConsole = new JPanel(new BorderLayout());
//add the text
JTextArea textArea = new JTextArea(5, 10);
Color bg = new Color(0,0,0);
textArea.setBackground(bg);
//Configure the text fonts
textArea.setFont(new Font("Serif", Font.ITALIC, 16));
textArea.setText(
"This is an editable JTextArea " +
"which reacts as the console."
);
//Set the wrap text option
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
//add the scrollbars
JScrollPane areaScrollPane = new JScrollPane(textArea);
areaScrollPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
return panelConsole;
}
So it means, I have to display my own messages and just want to make it look like a console but getting them form a library made in c++ which uses the command printf
Thanks