|
-
Nov 30th, 2003, 03:41 AM
#1
Thread Starter
Addicted Member
Panel problem...
I have made a panel and then added components to the panel. I then added the panel to a JScrollPane, which was added to a JFrame... The problem is that all the components in the panel appear to be frozen. They do respond to mouse clicks and key presses, but the changes are not made visible until the frame is repainted ( for ex. if i type something in one of the JTextFields i have, nothing appears to happen, but when i minimize the frame and then restore it, it shows the change, but the JTextField is still frozen. ) Any idea what is causing this problem... anyone?
To protect time is to protect everything...
-
Dec 4th, 2003, 01:55 AM
#2
Dazed Member
With this first code i add a JTextArea to a JScrollPane then add the JScrollPane to a JPanel. In this manner you are just getting Scrolling of the JTextArea.
Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Frame{
private JFrame jf;
private JPanel jp;
private JTextArea jta;
private JScrollPane jsp;
private Container c;
public Frame(String title){
jf = new JFrame(title);
jta = new JTextArea(10,10);
jp = new JPanel();
jsp = new JScrollPane(jta);
}
public void addListener(){
jf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent evt){
System.exit(0);
}
});
}
public void assemble(){
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
jp.add(jsp);
c = jf.getContentPane();
c.add(jp);
jf.setSize(300,200);
jf.setVisible(true);
}
}
public class X{
public static void main(String[] args){
Frame f = new Frame("Example");
f.addListener();
f.assemble();
}
}
In this next block of code im following somthing similar to what you are trying to do. Instead of adding the JTextArea to the JScrollPane i add the JPanel to the JScrollPane then i add the JTextArea to the JPanel. Either way works fine in the end. 
Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Frame{
private JFrame jf;
private JPanel jp;
private JTextArea jta;
private JScrollPane jsp;
private Container c;
public Frame(String title){
jf = new JFrame(title);
jta = new JTextArea(10,10);
jp = new JPanel();
jsp = new JScrollPane(jp);
}
public void addListener(){
jf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent evt){
System.exit(0);
}
});
}
public void assemble(){
jsp.setVerticalScrollBar(new JScrollBar(JScrollBar.VERTICAL));
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
jp.add(jta);
c = jf.getContentPane();
c.add(jsp);
jf.setSize(150,150);
jf.setVisible(true);
}
}
public class X{
public static void main(String[] args){
Frame f = new Frame("Example");
f.addListener();
f.assemble();
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|