I don't say that it is not possible but I have never seen a JTextArea with a awt.Layout
Assuming it is possible (the compiler does not complain and there are no run time error)
OK now you have a JTextArea with a GridLayout on 2 rows ?
You have add(histogram) and what else ? What goes on the second row.
How does a JTextArea, with a layout of 2 rows, knows where to add (in which row to add) the characters typed ?
This seems compilcated to me but again I might be completly wrong.
Why don't you simply set your JFrame with a GridLayout(2,1,1,1);
- add to the frame the JTextArea in its JScrollPane
- add the histogram
Then you will have your JTextArea in first row and your histogram in the second row.
I mean I don't see any sens of adding the JPanel where you draw into a JTextArea.
Also what you want is a KeyListener not a KeyAdapter
you will have to implement the 3 methods:
CODE
jta.addKeyListener(new KeyListener() {
/** Handle the button action */
public void keyPressed(KeyEvent e) {
// Count the letters in the text area
int[] count = countLetters();
// Set the letter count to histogram for display
histogram.showHistogram(count);
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
});
and the name of the method is keyPressed not KeyPressed (capital K).
This kind of work
java
public lab4()
{
setLayout(new GridLayout(2,1,1,1));
// Store text area in a scroll pane
jta = new JTextArea();
JScrollPane scrollPane = new JScrollPane(jta);
jta.setWrapStyleWord(true);
jta.setLineWrap(true);
jta.setPreferredSize(new Dimension(800,300));
add(scrollPane);
jta.addKeyListener(new KeyListener() {
/** Handle the button action */
public void keyPressed(KeyEvent e) {
// Count the letters in the text area
int[] count = countLetters();
// Set the letter count to histogram for display
histogram.showHistogram(count);
}
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
});
add(histogram);
}
Hope this help... I am anxious to see your solution.
This post has been edited by pbl: 18 Apr, 2008 - 11:23 AM