Skip to main content

Getting started with JFX + Swingx + GlazedLists

5 replies [Last post]
coxcu
Offline
Joined: 2003-06-11
Points: 0

Hi,

I have a small but useful application written using
GlazedLists and JXTable. I want to port it to JFX, but
I'm having trouble getting started. My first step is to
convert this trivial example program to use JXTable.

==========================================================
import javafx.ui.*;

class XTable extends Table {
protected operation createTable():
<>;
}

class Person {
attribute firstName: String;
}

class TableDemoModel {
attribute people: Person*;
}

var model = TableDemoModel {
people:
[Person {
firstName: "Mary"
}]
};

Frame {
height: 120
width: 500
title: "SimpleTableDemo"
content: XTable {
columns:
[TableColumn {
text: "First Name"
}]

cells: bind foreach (p in model.people)

[TableCell {
text:bind p.firstName
}]
}
visible: true
}
===========================================================

This appears to work, but I don't really know as no
JXTable behaviour is apparent. This seems like a nice experiment
for JFX, but so far I'm having trouble finding adequate
documentation and examples. The section on "Defining and
Extending Classes" doesn't tell me what I need.
http://openjfx.java.sun.com/current-build/doc/JavaFX-Language.html#d0e297

If anybody has gone down this path before and has some
code they would be willing to share, please let me know.

As a side note, I learned Swing largely through the Swing
Java trail. Is there going to be any effort to add JFX
versions of those examples?

Thanks,
Curt

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jim_weaver
Offline
Joined: 2007-05-18
Points: 0

Curt,

If I understand your question correctly, you need to wrap the JXTable in a JavaFX class. Here's a reply from Chris Oliver regarding a similar question:

"You can use custom JComponents in JFX by extending the Widget class and
implementing its createComponent() method to return an instanceof of your
custom JComponent, e.g:

import org.whatever.MyCustomSwingComponent;

class MyWidget extends Widget {
private attribute myComponent: MyCustomSwingComponent;

}

operation MyWidget.createComponent() {
myComponent = new MyCustomSwingComponent();
return myComponent;
}

Frame {
visible: true
content: MyWidget {
foreground: blue
background: red
}
}

Take a look at how the standard Swing components are wrapped in classes
derived from Widget under src/javafx/ui/*.fx.

Chris"

Thanks,

Jim Weaver
Author of recently published book:
"JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-Side Applications"
http://www.amazon.com/JavaFX-Script-Scripting-Client-side-Applications/d...
eBook (PDF) download: http://www.apress.com/book/view/1590599454

Learn JavaFX Weblog:
http://learnjavafx.typepad.com

coxcu
Offline
Joined: 2003-06-11
Points: 0

Jim,

Thanks for the reply. My first approach was actually to simply clone javafx.ui.Table substituting JXTable for JTable, but I couldn't get that to work for compiler errors that I don't understand.

That led me to the second approach of trying to extend javafx.ui.Table. Unfortunately, javafx.ui.Table currently falls short of the Java ideal of making extension designed for and documented or prohibited. The big problem is that my knowledge of how to extend a JFX class is near zero.

I'll try both strategies again.

Thanks,
Curt

jim_weaver
Offline
Joined: 2007-05-18
Points: 0

Curt,

Do you understand the approach that Chris is suggesting? If not, I'll work up a quick code sample for you and post it.

Thanks,
Jim Weaver

coxcu
Offline
Joined: 2003-06-11
Points: 0

I understand the general approach, but not the details. As far as I can tell, both approaches that I mentioned fall within the outline Chris suggested.

javafx.ui.Table does what Chris is suggesting, albeit indirectly through javafx.ui.ScrollableWidget. Since JXTable extends JTable, I should be able to extend javafx.ui.Table to make something that provides all the JTable support of the current implementation, plus additional support for JXTable sorting and (painless user-driven) column hiding.

With all of that said, sample code would indeed be welcome.

jim_weaver
Offline
Joined: 2007-05-18
Points: 0

Curt,

Here is a very basic start to a JavaFX custom component that wraps a JXTable. Please let me know if you have any questions.

import javafx.ui.*;
import org.jdesktop.swingx.JXTable;

class XTable extends Widget {
private attribute xTable:JXTable;
public attribute rows:Integer;
public attribute columns:Integer;
}

operation XTable.createComponent():<> {
xTable = new JXTable(rows, columns);
return xTable;
}

Frame {
title: "Create a JXTable Custom Component"
visible: true
background: white
content: XTable {
rows: 20
columns: 4
}
}

Please reply if you have any questions,
Jim Weaver