This page is no longer maintained — Please continue to the home page at www.scala-lang.org

JFrame in scala.swing

3 replies
Charles F. Munat
Joined: 2008-12-29,
User offline. Last seen 42 years 45 weeks ago.

I have an org.jfree.chart.ChartFrame which extends javax.swing.JFrame
and I want to display it using scala.swing. Is there some way I can make
this work?

http://www.jfree.org/jfreechart/api/javadoc/index.html

java.lang.Object
extended by java.awt.Component
extended by java.awt.Container
extended by java.awt.Window
extended by java.awt.Frame
extended by javax.swing.JFrame
extended by org.jfree.chart.ChartFrame

I'm hoping to display a pie chart in a BorderPanel.

Thanks!

Chas. Munat

imaier
Joined: 2008-07-01,
User offline. Last seen 23 weeks 2 days ago.
Re: JFrame in scala.swing

I am not sure I understand what you want to do and where the problem is.
I am not familiar with JFreeChart either. Could you elaborate?

Thanks
Ingo

Charles F. Munat wrote:
> I have an org.jfree.chart.ChartFrame which extends javax.swing.JFrame
> and I want to display it using scala.swing. Is there some way I can make
> this work?
>
> http://www.jfree.org/jfreechart/api/javadoc/index.html
>
> java.lang.Object
> extended by java.awt.Component
> extended by java.awt.Container
> extended by java.awt.Window
> extended by java.awt.Frame
> extended by javax.swing.JFrame
> extended by org.jfree.chart.ChartFrame
>
> I'm hoping to display a pie chart in a BorderPanel.
>
> Thanks!
>
> Chas. Munat

Charles F. Munat
Joined: 2008-12-29,
User offline. Last seen 42 years 45 weeks ago.
Re: JFrame in scala.swing

Sorry to reply to my own message, but I figured it out. ChartFrame is a
JFrame, but JFrame is *not* a JComponent. However, JFreeCharts offers a
ChartPanel, which is a JPanel, thus a JComponent. A simple
Component.wrap(chart) and it works.

Somehow I thought it would be more difficult. Scala really kicks ass.

Thanks!

Chas. Munat

Charles F. Munat wrote:
> I have an org.jfree.chart.ChartFrame which extends javax.swing.JFrame
> and I want to display it using scala.swing. Is there some way I can make
> this work?
>
> http://www.jfree.org/jfreechart/api/javadoc/index.html
>
> java.lang.Object
> extended by java.awt.Component
> extended by java.awt.Container
> extended by java.awt.Window
> extended by java.awt.Frame
> extended by javax.swing.JFrame
> extended by org.jfree.chart.ChartFrame
>
> I'm hoping to display a pie chart in a BorderPanel.
>
> Thanks!
>
> Chas. Munat

mailleux
Joined: 2008-08-23,
User offline. Last seen 4 years 7 weeks ago.
Re: JFrame in scala.swing


On Wed, Mar 4, 2009 at 8:22 PM, Charles F. Munat <chas@munat.com> wrote:
Sorry to reply to my own message, but I figured it out. ChartFrame is a JFrame, but JFrame is *not* a JComponent. However, JFreeCharts offers a ChartPanel, which is a JPanel, thus a JComponent. A simple Component.wrap(chart) and it works.

One thing that may work is to create a  scala.swing version ChartFrame. I may be wrong but a lot of the classes in scala.swing are components wrapping a JComponent or JFrame and adding a set of traits. It may actually be easy to get some class that inherits JFrame and add the traits and wrapping you need. Whenever in doubt I look at the scala.swing source for inspiration (and amazement) on how to do things.

 

Somehow I thought it would be more difficult. Scala really kicks ass.


Agreed, and I really like the scala.swing way of doing things.

Thomas

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland