Skip to main content

java.util.ArrayList problem

5 replies [Last post]
mishela
Offline
Joined: 2007-08-18
Points: 0

Hello, I have a little problem. I have an ArrayList in Java and in this ArrayList are paths to some files (gif) that are drawing in a window.
For example:

ArrayList arrayList = new ArrayList();
arrayList.add("path/1.gif");
arrayList.add("path/2.gif");
...

and in a JPanel:

public void paintComponent(Graphics g) {
super.paintComponent(g);
for (int i = 0; i < arrayList.size(); i++) {
new ImageIcon("arrayList.get(i)").paintIcon(this, g, 0, 0+i*);
}

Reply viewing options

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

And when I do this: arrayList.add("path/4.gif"); and call the repaint() method, the view changes dynamically (I use java.beans.PropertyChangeListener).
I need this to do in JavaFX, but I don't know how to dynamically change the view in the frame according to the content of the ArrayList. Is there something like

Frame {
content: Canvas {
content: bind for(...) {
...
}
}
}

or something similar? Thanks forward for advices.

I'm sorry for the splitted message but it was not correctly viewed in the forum because the text was too long.

alexsch
Offline
Joined: 2007-07-12
Points: 0

You are right. It needs to use [b]bind[/b] operator before image iteration.

For example:

[code]
import javafx.ui.*;
import javafx.ui.canvas.*;

var list = [ "path/1.gif", "path/2.gif" ];

var ind = 3;

Frame{
content: BorderPanel{

center: Canvas{
content: bind for (url in list)
ImageView{
transform: Transform.translate( indexof url * 50, indexof url * 50)
image: Image {
url: url
}
}
}
bottom: Button{
text: "Add Image"
action: function(){
insert "path/{ind}.gif" into list;
ind ++;
}
}
}
visible: true
}
[/code]

mishela
Offline
Joined: 2007-08-18
Points: 0

Thank you, but is this working for java.util.ArrayList too? I must use this class because the whole program ist built on this. Thanks.

alexsch
Offline
Joined: 2007-07-12
Points: 0

The direct binding does not work with Java objects.

So it needs to convert ArrayList to JavaFX sequence.

For example:

[code]
import java.util.ArrayList ;

var list:String[];
var arrayList = new ArrayList ();

arrayList.add("One");
arrayList.add("Two");
arrayList.add("Three");

var iterator = arrayList.iterator();

while(iterator.hasNext()){
insert iterator.next() as String into list;
}
[/code]

mishela
Offline
Joined: 2007-08-18
Points: 0

thanks :)
this solution of JavaFX isn't very good, Sun should do something with that...