When I try to put the JTextArea in a JScrollPane, it a) doesn't display the menu most of the time, and b) doesn't display the scroll bars, even though I've got more text than the size of the JTextArea.
Code (it's a VERY simple error console for something else):
import java.awt.Dimension;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class ErrorConsole extends JFrame {
JPanel pan = new JPanel();
private static final long serialVersionUID = 1L;
JTextArea ar = new JTextArea("");
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Tools");
JMenuItem clear = new JMenuItem("Clear");
JMenuItem close = new JMenuItem("Quit");
JMenuItem post = new JMenuItem("Manual Post");
JFrame postFrame = new JFrame("Post");
JTextField fil = new JTextField("Post Here");
JButton cont = new JButton("Post!");
JPanel postPanel = new JPanel();
void postWindow() {
postFrame.setVisible(true);
}
public ErrorConsole(String title) {
this.setTitle(title);
//JScrollPane js = new JScrollPane(ar);
JScrollPane scrollPane =
new JScrollPane(ar);
//pan.add(scrollPane);
pan.add(ar);
ar.setEditable(false);
this.setResizable(false);
ar.setPreferredSize(new Dimension(300, 252));
this.setSize(325, 324);
add(pan);
ar.setText("*"+title + "*\n");
this.setVisible(true);
menuBar.add(menu);
menu.add(post);
menu.add(clear);
menu.add(close);
fil.setColumns(20);
postFrame.pack();
post.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
postWindow();
}
});
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setJMenuBar(menuBar);
postFrame.add(postPanel);
postPanel.add(fil);
postPanel.add(cont);
cont.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
post(fil.getText() + "\n");
}
});
}
/**
* Posts to the JList
*
* @param text
* @param type
*/
public void post(String text) {
ar.append(text);
}
public void clear() {
ar.setText("");
}
public void close() {
clear();
setVisible(false);
System.gc();
}
}
Thanks!
Jack