Does anyone know what a Content Pane is? Can a component
be added to a JFrame directly or do i have to add it to a content pane first? Im just not sure about the purpose of a Content Pane.
Printable View
Does anyone know what a Content Pane is? Can a component
be added to a JFrame directly or do i have to add it to a content pane first? Im just not sure about the purpose of a Content Pane.
For instance this code produces a runtime error. Do i have to
add the components to a panel then add the panel to a Content Pane then add the content pane to a JFrame? Writing GUI's in Java can be a real pain in the ass. :p
Code:import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Test{
public static void main(String[] args){
JFrame jf = new JFrame("A Frame");
JPanel jp = new JPanel();
JButton jb = new JButton("A Button");
JTextArea jta1 = new JTextArea();
JTextArea jta2 = new JTextArea();
jp.setLayout(new GridLayout(1,2));
jp.add(jb);
jp.add(jta1);
jp.add(jta2);
jf.add(jp);
jf.setSize(600,300);
jf.setVisible(true);
jf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}
Never mind i got it. ;)