Menu

#3 Can´t add empty JScrollPane to Tabpane

open
nobody
5
2008-07-09
2008-07-09
oraether
No

hey,

the follow simple app runs into an NullPointer Exception

package test.charva;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import charva.awt.BorderLayout;
import charva.awt.Dimension;
import charvax.swing.JButton;
import charvax.swing.JFrame;
import charvax.swing.JPanel;
import charvax.swing.JScrollPane;
import charvax.swing.JTabbedPane;
import charvax.swing.JTable;
import charvax.swing.JTextArea;
import charvax.swing.table.DefaultTableModel;

public class TestSwing extends JFrame
{
private static final Log LOG = LogFactory.getLog(TestSwing.class);
DefaultTableModel dftm = new DefaultTableModel(
new String[][]{{"Action","Face/Off"},
{"Kung Fu","Fist of the Legend"}},
new String[]{"property name","value"});

public TestSwing() {
super();
this.setTitle("Hello World Again !");
this.setSize(50, 20);
JPanel panel = new JPanel();
this.add(panel);
panel.setLayout(new BorderLayout());
JTabbedPane tabpane = new JTabbedPane();
JScrollPane scrollpane = new JScrollPane();
tabpane.addTab("About", null, scrollpane,"");
panel.add(tabpane, BorderLayout.CENTER);
JTextArea textarea = new JTextArea("Hallo");
scrollpane.setViewportView(textarea);
JTable table = new JTable();
table.setPreferredScrollableViewportSize(new Dimension(25,5));
tabpane.addTab("Table", null, table,"");
table.setModel(dftm);
JPanel panel2 = new JPanel();
panel.add(panel2, BorderLayout.SOUTH);
JButton jbut2 = new JButton();
jbut2.setText("OK");
panel2.add(jbut2);
this.setVisible(true);
}

public static void main(String[] args)
{
LOG.info("...");
TestSwing ts = new TestSwing();
}

}

Running this app the following Exception occurs:
--------------------------------------------------------
Exception in thread "main" java.lang.NullPointerException
at charvax.swing.JScrollPane.minimumSize(JScrollPane.java:134)
at charvax.swing.JTabbedPane.minimumSize(JTabbedPane.java:182)
at charvax.swing.JTabbedPane.getSize(JTabbedPane.java:163)
at
....
--------------------------------------------------------------

Looking in this line the problem comes up:

It´s not possible to ad an empty Scrollpane to an Tabpane.

So i modified the a source a bit and everything is fine:

---JScrollpane.java Line 131 -------------------------
if(view == null)
size.setSize(super.minimumSize());
else
size.setSize(view.getSize()); // original code
-----------------------------------------------------

Hope someone is looking at it and modifies the code

Olaf

Discussion


Log in to post a comment.