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

scala.swing.Table usage?

5 replies
vladev
Joined: 2009-04-22,
User offline. Last seen 2 years 16 weeks ago.

Hi, I've been struggling for a while with the usage of the Table class
in the swing package.

Here is the pasted code, nicely formatted:
http://paste.pocoo.org/show/122911/

Could be my Scala skills letting me down, but... I have no clue.

import scala.swing._

object Gui {
def main(args: Array[String]) {
var initial = Array(
Array("John", "Doe", "26"),
Array("Jim", "Smith", "55"),
Array("Robert", "Lang", "43"))

val names = Array("First name", "Last name", "Age")

var memTable = new Table(initial, names)

/**
* Doesn't even compile:
* Gui.scala:12: error: overloaded method constructor Table with
alternatives
* (Int,Int)scala.swing.Table
* (Array[Array[Any]],Seq[Any])scala.swing.Table cannot be applied to
* (Array[Array[java.lang.String]],Array[java.lang.String])
* var memTable = new Table(initial, names)
* ^
* one error found
*/

val main = new MainFrame {
contents = memTable
}
main.visible = true
}
}

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: scala.swing.Table usage?

On Sat, Jun 13, 2009 at 10:53:38PM +0300, Емил Иванов / Emil Ivanov wrote:
> /**
> * Doesn't even compile:
> * Gui.scala:12: error: overloaded method constructor Table with
> alternatives
> * (Int,Int)scala.swing.Table
> * (Array[Array[Any]],Seq[Any])scala.swing.Table cannot be applied to
> * (Array[Array[java.lang.String]],Array[java.lang.String])

I don't know anything about scala swing, but that doesn't work because
like it says, you're passing an Array[Array[String]] and it wants an
Array[Array[Any]]. Arrays aren't covariant.

Create them like Array[Any]("foo", "bar", ...) and at least it will
compile.

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: scala.swing.Table usage?

On Sat, Jun 13, 2009 at 10:53:38PM +0300, Емил Иванов / Emil Ivanov wrote:
> * Gui.scala:12: error: overloaded method constructor Table with
> alternatives
> * (Int,Int)scala.swing.Table
> * (Array[Array[Any]],Seq[Any])scala.swing.Table cannot be applied to
> * (Array[Array[java.lang.String]],Array[java.lang.String])

Also, if the Table constructor is rewritten something more like this:

def this(_rowData: Array[_ <: Array[_]], _columnNames: Seq[_]) = {
this()
val rowData = _rowData.asInstanceOf[Array[Array[Any]]]
val columnNames = _columnNames.asInstanceOf[Seq[Any]]

it should allow you to call it the way you're calling it without
altering anything else. I don't want to modify it because in my swingy
ignorance I could easily be overlooking something, but if I'm not maybe
that will turn up down the road.

vladev
Joined: 2009-04-22,
User offline. Last seen 2 years 16 weeks ago.
Re: scala.swing.Table usage?
Ok, I got it to compile and the data shows, but there are no headers?

import scala.swing._

object Gui {
 def main(args: Array[String]) {
   var initial = Array(
     Array("John", "Doe", "26"),
     Array("Jim", "Smith", "55"),
     Array("Robert", "Lang", "43"))

   val names = Array("First name", "Last name", "Age")

   var memTable = new Table(initial.asInstanceOf[Array[Array[Any]]], names.asInstanceOf[Array[Any]])

   val main = new MainFrame {
     contents = memTable
   }
   main.visible = true
 }
}

Regards

2009/6/13 Paul Phillips <paulp [at] improving [dot] org>:
> On Sat, Jun 13, 2009 at 10:53:38PM +0300, Емил Иванов / Emil Ivanov wrote:
>>      * Gui.scala:12: error: overloaded method constructor Table with
>> alternatives
>>      * (Int,Int)scala.swing.Table <and>
>>      * (Array[Array[Any]],Seq[Any])scala.swing.Table cannot be applied to
>>      * (Array[Array[java.lang.String]],Array[java.lang.String])
>
> Also, if the Table constructor is rewritten something more like this:
>
>  def this(_rowData: Array[_ <: Array[_]], _columnNames: Seq[_]) = {
>    this()
>    val rowData = _rowData.asInstanceOf[Array[Array[Any]]]
>    val columnNames = _columnNames.asInstanceOf[Seq[Any]]
>
> it should allow you to call it the way you're calling it without
> altering anything else.  I don't want to modify it because in my swingy
> ignorance I could easily be overlooking something, but if I'm not maybe
> that will turn up down the road.
>
> --
> Paul Phillips      | One way is to make it so simple that there are
> Stickler           | obviously no deficiencies. And the other way is to make
> Empiricist         | it so complicated that there are no obvious deficiencies.
> i pull his palp!   |     -- Hoare
>



--
My place to share my ideas:
http://bolddream.com (now live :)

Paul Chiusano
Joined: 2009-01-01,
User offline. Last seen 42 years 45 weeks ago.
Re: scala.swing.Table usage?
The headers only show up if you put it in a scrollpanel... this is actually a swing behavior... don't ask me why the heck swing does this, though. See the JTable docs for more info:
Note that if you wish to use a JTable in a standalone view (outside of a JScrollPane) and want the header displayed, you can get it using getTableHeader() and display it separately.
 Paul
2009/6/14 Емил Иванов / Emil Ivanov <emil [dot] vladev [at] gmail [dot] com>
Ok, I got it to compile and the data shows, but there are no headers?

import scala.swing._

object Gui {
 def main(args: Array[String]) {
   var initial = Array(
     Array("John", "Doe", "26"),
     Array("Jim", "Smith", "55"),
     Array("Robert", "Lang", "43"))

   val names = Array("First name", "Last name", "Age")

   var memTable = new Table(initial.asInstanceOf[Array[Array[Any]]], names.asInstanceOf[Array[Any]])

   val main = new MainFrame {
     contents = memTable
   }
   main.visible = true
 }
}

Regards

2009/6/13 Paul Phillips <paulp [at] improving [dot] org>:
> On Sat, Jun 13, 2009 at 10:53:38PM +0300, Емил Иванов / Emil Ivanov wrote:
>>      * Gui.scala:12: error: overloaded method constructor Table with
>> alternatives
>>      * (Int,Int)scala.swing.Table <and>
>>      * (Array[Array[Any]],Seq[Any])scala.swing.Table cannot be applied to
>>      * (Array[Array[java.lang.String]],Array[java.lang.String])
>
> Also, if the Table constructor is rewritten something more like this:
>
>  def this(_rowData: Array[_ <: Array[_]], _columnNames: Seq[_]) = {
>    this()
>    val rowData = _rowData.asInstanceOf[Array[Array[Any]]]
>    val columnNames = _columnNames.asInstanceOf[Seq[Any]]
>
> it should allow you to call it the way you're calling it without
> altering anything else.  I don't want to modify it because in my swingy
> ignorance I could easily be overlooking something, but if I'm not maybe
> that will turn up down the road.
>
> --
> Paul Phillips      | One way is to make it so simple that there are
> Stickler           | obviously no deficiencies. And the other way is to make
> Empiricist         | it so complicated that there are no obvious deficiencies.
> i pull his palp!   |     -- Hoare
>



--
My place to share my ideas:
http://bolddream.com (now live :)


vladev
Joined: 2009-04-22,
User offline. Last seen 2 years 16 weeks ago.
Re: scala.swing.Table usage?
Dohh...

Thank you Paul and Paul. :)

2009/6/15 Paul Chiusano <paul [dot] chiusano [at] gmail [dot] com>
The headers only show up if you put it in a scrollpanel... this is actually a swing behavior... don't ask me why the heck swing does this, though. See the JTable docs for more info:
Note that if you wish to use a JTable in a standalone view (outside of a JScrollPane) and want the header displayed, you can get it using getTableHeader() and display it separately.
 Paul
2009/6/14 Емил Иванов / Emil Ivanov <emil [dot] vladev [at] gmail [dot] com>
Ok, I got it to compile and the data shows, but there are no headers?

import scala.swing._

object Gui {
 def main(args: Array[String]) {
   var initial = Array(
     Array("John", "Doe", "26"),
     Array("Jim", "Smith", "55"),
     Array("Robert", "Lang", "43"))

   val names = Array("First name", "Last name", "Age")

   var memTable = new Table(initial.asInstanceOf[Array[Array[Any]]], names.asInstanceOf[Array[Any]])

   val main = new MainFrame {
     contents = memTable
   }
   main.visible = true
 }
}

Regards

2009/6/13 Paul Phillips <paulp [at] improving [dot] org>:
> On Sat, Jun 13, 2009 at 10:53:38PM +0300, Емил Иванов / Emil Ivanov wrote:
>>      * Gui.scala:12: error: overloaded method constructor Table with
>> alternatives
>>      * (Int,Int)scala.swing.Table <and>
>>      * (Array[Array[Any]],Seq[Any])scala.swing.Table cannot be applied to
>>      * (Array[Array[java.lang.String]],Array[java.lang.String])
>
> Also, if the Table constructor is rewritten something more like this:
>
>  def this(_rowData: Array[_ <: Array[_]], _columnNames: Seq[_]) = {
>    this()
>    val rowData = _rowData.asInstanceOf[Array[Array[Any]]]
>    val columnNames = _columnNames.asInstanceOf[Seq[Any]]
>
> it should allow you to call it the way you're calling it without
> altering anything else.  I don't want to modify it because in my swingy
> ignorance I could easily be overlooking something, but if I'm not maybe
> that will turn up down the road.
>
> --
> Paul Phillips      | One way is to make it so simple that there are
> Stickler           | obviously no deficiencies. And the other way is to make
> Empiricist         | it so complicated that there are no obvious deficiencies.
> i pull his palp!   |     -- Hoare
>



--
My place to share my ideas:
http://bolddream.com (now live :)





--
My place to share my ideas:
http://bolddream.com (now live :)

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