Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Mac OS X: Problems with custom widget in JTable

3 views
Skip to first unread message

Felix Natter

unread,
Nov 30, 2009, 2:56:01 PM11/30/09
to
hello,

I am using a simple "graph widget" (a subclass of JComponent that
overrides the paint() method) as a cell renderer in a simple
JTable.

This works fine on Linux and Windows (you see the /\ /\ in each cell),
but on Mac OS X (also with Java 1.6) the cells are empty (just plain
white window).

A minimal example that shows this behavior is attached.
Do you have any ideas?

Thanks in advance!
--
Felix Natter

TestJTable5.java

John B. Matthews

unread,
Nov 30, 2009, 4:24:37 PM11/30/09
to
In article <87bpij3...@etchy.mobile.lcn>,
Felix Natter <felix....@smail.inf.fh-brs.de> wrote:

[...]
> public void paint(Graphics g) {

Override paintComponent():

<http://java.sun.com/products/jfc/tsc/articles/painting/index.html>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

Thomas A. Russ

unread,
Nov 30, 2009, 5:26:22 PM11/30/09
to
"John B. Matthews" <nos...@nospam.invalid> writes:

> In article <87bpij3...@etchy.mobile.lcn>,
> Felix Natter <felix....@smail.inf.fh-brs.de> wrote:
>
> > I am using a simple "graph widget" (a subclass of JComponent that
> > overrides the paint() method) as a cell renderer in a simple JTable.
> >
> > This works fine on Linux and Windows (you see the /\ /\ in each
> > cell), but on Mac OS X (also with Java 1.6) the cells are empty (just
> > plain white window).
> >
> > A minimal example that shows this behavior is attached. Do you have
> > any ideas?
> [...]
> > public void paint(Graphics g) {
>
> Override paintComponent():
>
> <http://java.sun.com/products/jfc/tsc/articles/painting/index.html>

And I just confirmed that that will work on MacOS X, with Java 1.6
(Tested with OS 10.5, Intel HW)


--
Thomas A. Russ, USC/Information Sciences Institute


Lew

unread,
Nov 30, 2009, 9:31:00 PM11/30/09
to
Felix Natter wrote:
> I am using a simple "graph widget" (a subclass of JComponent that
> overrides the paint() method) as a cell renderer in a simple
> JTable.
>
> This works fine on Linux and Windows (you see the /\ /\ in each cell),
> but on Mac OS X (also with Java 1.6) the cells are empty (just plain
> white window).

Others have addressed the main points, but I see another problem - you aren't
doing GUI on the Event Dispatch Thread (EDT).

public static void main(String[] args) {
TestJTable5 frame = new TestJTable5();
frame.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
System.exit(0);
}
});
//frame.pack();
frame.setVisible(true);
}

All those GUI calls and constructors should be moved to the EDT, most easily
by using java.awt.EventQueue.invokeLater() of a new Runnable around the calls
in your main().

--
Lew

0 new messages