Question about JTextAreas
To: comp.lang.java.gui
I'm starting to piece my way through the construction of a GUI which
has 4 buttons (add, change, delete, print) and a JTextArea that
displays the contents of a file using a vertical scroll bar.
I'm not sure what I'm doing wrong here, but when I add panel2 my
buttons disappear. If I leave it off the frame, my buttons stay where
I put them. I left out the part of the program that parses the XML
file and checks for wellformedness just to keep the code compact
package mainPackage;
// omitted a bunch of imports
public class printControlMaintenanceGUI {
public static void main(String[] args) throws FileNotFoundException,
IOException {
// TODO Auto-generated method stub
MainFrame frame = new MainFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class MainFrame extends JFrame
{
public MainFrame() throws FileNotFoundException, IOException
{
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
int screenHeight = screenSize.height;
int screenWidth = screenSize.width;
setSize(screenWidth/2, screenHeight/2);
setLocation(screenWidth/4, screenHeight/4);
ButtonPanel panel1 = new ButtonPanel();
add(panel1);
TextPanel panel2 = new TextPanel();
// if I let this happen, my buttons disappear add(panel2);
}
}
class TextPanel extends JPanel
{
public TextPanel() throws FileNotFoundException, IOException
{
ArrayList pcControl = new ArrayList<String>();
JTextArea currentList = new JTextArea("",20,80);
pcControl=loadXMLFile(); <-- I left this code out because it works.
displayXMLFile(pcControl, currentList);
add(currentList);
}
public static void displayXMLFile(ArrayList aList, JTextArea ta)
{
String newLine = "\n";
for (int tt=0;tt<=aList.size() - 1;tt++)
{
String line2 = (String) aList.get(tt);
System.out.println("Line: " + tt + " " + line2);
ta.append(line2 );
ta.append(newLine);
}
}
// left out to make the attachment smaller
// end of ommitted stuff
}
class ButtonPanel extends JPanel
{
public ButtonPanel()
{
JButton addButton = new JButton("Add");
JButton changeButton = new JButton("Change");
JButton deleteButton = new JButton("Delete");
JButton printButton = new JButton("Print");
add(addButton);
add(changeButton);
add(deleteButton);
add(printButton);
}
}
Remember, I'm just starting this.. putting it together piece by piece.
I started by getting the JFrame working, then the buttons. The last
thing I did was set up the TextArea and append the strings I read in to
it. It "looks" like it works but I won't know for sure until I can
have both the TextArea and the buttons on the screen at the same time.
I've tried setting the location of the text panel using the setLocation
method, but it still doesn't work.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24