- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
scala.swing.Table usage?
Sat, 2009-06-13, 20:54
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
}
}
Sat, 2009-06-13, 21:27
#2
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.
Sun, 2009-06-14, 10:07
#3
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 :)
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 :)
Mon, 2009-06-15, 16:17
#4
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:
2009/6/14 Емил Иванов / Emil Ivanov <emil [dot] vladev [at] gmail [dot] com>
Note that if you wish to use aPaulJTable
in a standalone view (outside of aJScrollPane
) and want the header displayed, you can get it usinggetTableHeader()
and display it separately.
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 :)
Tue, 2009-06-16, 09:47
#5
Re: scala.swing.Table usage?
Dohh...
Thank you Paul and Paul. :)
2009/6/15 Paul Chiusano <paul [dot] chiusano [at] gmail [dot] com>
--
My place to share my ideas:
http://bolddream.com (now live :)
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 aPaulJTable
in a standalone view (outside of aJScrollPane
) and want the header displayed, you can get it usinggetTableHeader()
and display it separately.
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 :)
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.