Re: Can anyone tell me what the following error mean? and how to fix it?

In Swing , you cannot call the setLayout( ) method direct from JFrame , like
the one below:

javax.swing.JFrame.setLayout(new BorderLayout()) ,

This is because you cannot add containers directly to the JFrame;

Use the following line always as advised in the Exception message of your

javax.swing.JFrame.getContentPane().setLayout(new BorderLayout()):


public static void main(String[] args){

  JFrame frame = new JFrame("Frame");
  JPanel panel = new JPanel(new GridLayout());
  frame.getContentPane.setLayout(new BorderLayout()); //correct
  //frame.setLayout(new BorderLayout());

  frame.getContentPane.add(panel,BorderLayout.CENTER);  //correct
  // frame.add(panel, BorderLayout.CENTER):

Hope it helps,

----- Original Message -----
From: "Helen Yi" <y.yi@xxxxxxxxxxxxx>
To: <visad-list@xxxxxxxxxxxxx>
Sent: Wednesday, February 13, 2002 8:39 AM
Subject: Can anyone tell me what the following error mean? and how to fix

> I try to run the WidgetTest of visad's util package, but got the
> following error
> helen@virga [87] j/users/helen/VisAD/ava visad.util.WidgetTest
> Exception in thread "main" java.lang.Error: Do not use
> javax.swing.JFrame.setLayout() use
> javax.swing.JFrame.getContentPane().setLayout() instead
>         at javax.swing.JFrame.createRootPaneException(,
> Compiled Code)
>         at javax.swing.JFrame.setLayout(, Compiled Code)
>         at visad.util.WidgetTest.main(, Compiled Code)
> I got the same error as above when I am running VisAD on SGI Octane and
> Windows 2000.
> Please help me to fix the problem. Great thanks in advance.
> Helen

  • 2002 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: