回答編集履歴
1
見直しキャンペーン中
answer
CHANGED
@@ -1,106 +1,106 @@
|
|
1
|
-
> Groupを使えば良いとのことだったのですが、
|
2
|
-
|
3
|
-
JavaFXはあまりわかっていないのですが、`Group`はただグループ化するだけで重なってしまいませんか?
|
4
|
-
|
5
|
-
どういう表示のイメージかわかりませんが、基本的には`ScrollPane`の中に何かしらのレイアウト(`VBox`等)を入れ、その中に`ImageView`や`Text`を入れればいいと思います。
|
6
|
-
|
7
|
-
```
|
8
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
9
|
-
|
10
|
-
<?import javafx.scene.control.Button?>
|
11
|
-
<?import javafx.scene.control.ScrollPane?>
|
12
|
-
<?import javafx.scene.image.Image?>
|
13
|
-
<?import javafx.scene.image.ImageView?>
|
14
|
-
<?import javafx.scene.layout.BorderPane?>
|
15
|
-
<?import javafx.scene.layout.VBox?>
|
16
|
-
<?import javafx.scene.text.Text?>
|
17
|
-
|
18
|
-
|
19
|
-
<BorderPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1"
|
20
|
-
xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
|
21
|
-
<top>
|
22
|
-
<Button mnemonicParsing="false" onAction="#onButton" text="add" BorderPane.alignment="CENTER"/>
|
23
|
-
</top>
|
24
|
-
<center>
|
25
|
-
<ScrollPane>
|
26
|
-
<content>
|
27
|
-
<VBox fx:id="vbox">
|
28
|
-
<children>
|
29
|
-
<ImageView>
|
30
|
-
<image>
|
31
|
-
<Image url="https://teratail-v2.storage.googleapis.com/uploads/avatars/u17/171983/5c373ecbfa1165eb_thumbnail.jpeg"/>
|
32
|
-
</image>
|
33
|
-
</ImageView>
|
34
|
-
<Text text="Text"/>
|
35
|
-
<ImageView>
|
36
|
-
<image>
|
37
|
-
<Image url="https://teratail-v2.storage.googleapis.com/uploads/avatars/u13/132786/KnkDDC5A_thumbnail.jpg"/>
|
38
|
-
</image>
|
39
|
-
</ImageView>
|
40
|
-
</children>
|
41
|
-
</VBox>
|
42
|
-
</content>
|
43
|
-
</ScrollPane>
|
44
|
-
</center>
|
45
|
-
</BorderPane>
|
46
|
-
```
|
47
|
-
|
48
|
-
```Java
|
49
|
-
package sample;
|
50
|
-
|
51
|
-
import javafx.event.ActionEvent;
|
52
|
-
import javafx.fxml.FXML;
|
53
|
-
import javafx.scene.image.Image;
|
54
|
-
import javafx.scene.image.ImageView;
|
55
|
-
import javafx.scene.layout.VBox;
|
56
|
-
import javafx.scene.text.Text;
|
57
|
-
|
58
|
-
public class Controller {
|
59
|
-
private static final String url1 = "https://teratail-v2.storage.googleapis.com/uploads/avatars/u17/171983/5c373ecbfa1165eb_thumbnail.jpeg";
|
60
|
-
private static final String url2 = "https://teratail-v2.storage.googleapis.com/uploads/avatars/u13/132786/KnkDDC5A_thumbnail.jpg";
|
61
|
-
|
62
|
-
@FXML
|
63
|
-
private VBox vbox;
|
64
|
-
|
65
|
-
@FXML
|
66
|
-
void onButton(ActionEvent event) {
|
67
|
-
vbox.getChildren().add(new ImageView(new Image(url1)));
|
68
|
-
vbox.getChildren().add(new Text("Text"));
|
69
|
-
vbox.getChildren().add(new ImageView(new Image(url2)));
|
70
|
-
}
|
71
|
-
}
|
72
|
-
```
|
73
|
-
|
74
|
-
```Java
|
75
|
-
package sample;
|
76
|
-
|
77
|
-
import javafx.application.Application;
|
78
|
-
import javafx.fxml.FXMLLoader;
|
79
|
-
import javafx.scene.Parent;
|
80
|
-
import javafx.scene.Scene;
|
81
|
-
import javafx.stage.Stage;
|
82
|
-
|
83
|
-
public class Main extends Application {
|
84
|
-
@Override
|
85
|
-
public void start(Stage primaryStage) throws Exception {
|
86
|
-
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
|
87
|
-
primaryStage.setScene(new Scene(root, 300, 275));
|
88
|
-
primaryStage.show();
|
89
|
-
}
|
90
|
-
|
91
|
-
public static void main(String[] args) {
|
92
|
-
launch(args);
|
93
|
-
}
|
94
|
-
}
|
95
|
-
```
|
96
|
-

|
97
|
-
|
98
|
-
---
|
99
|
-
|
100
|
-
> 調べてみたところ、
|
101
|
-
|
102
|
-
調べたことを具体的に提示してください(見たURLや、自分で試したコード等)
|
103
|
-
「調べましたが」だけでは、第3者には全く伝わりません。
|
104
|
-
|
105
|
-
まだ読んでいなければこちらを一通り目を通してください。
|
1
|
+
> Groupを使えば良いとのことだったのですが、
|
2
|
+
|
3
|
+
JavaFXはあまりわかっていないのですが、`Group`はただグループ化するだけで重なってしまいませんか?
|
4
|
+
|
5
|
+
どういう表示のイメージかわかりませんが、基本的には`ScrollPane`の中に何かしらのレイアウト(`VBox`等)を入れ、その中に`ImageView`や`Text`を入れればいいと思います。
|
6
|
+
|
7
|
+
```xml
|
8
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
9
|
+
|
10
|
+
<?import javafx.scene.control.Button?>
|
11
|
+
<?import javafx.scene.control.ScrollPane?>
|
12
|
+
<?import javafx.scene.image.Image?>
|
13
|
+
<?import javafx.scene.image.ImageView?>
|
14
|
+
<?import javafx.scene.layout.BorderPane?>
|
15
|
+
<?import javafx.scene.layout.VBox?>
|
16
|
+
<?import javafx.scene.text.Text?>
|
17
|
+
|
18
|
+
|
19
|
+
<BorderPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/11.0.1"
|
20
|
+
xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
|
21
|
+
<top>
|
22
|
+
<Button mnemonicParsing="false" onAction="#onButton" text="add" BorderPane.alignment="CENTER"/>
|
23
|
+
</top>
|
24
|
+
<center>
|
25
|
+
<ScrollPane>
|
26
|
+
<content>
|
27
|
+
<VBox fx:id="vbox">
|
28
|
+
<children>
|
29
|
+
<ImageView>
|
30
|
+
<image>
|
31
|
+
<Image url="https://teratail-v2.storage.googleapis.com/uploads/avatars/u17/171983/5c373ecbfa1165eb_thumbnail.jpeg"/>
|
32
|
+
</image>
|
33
|
+
</ImageView>
|
34
|
+
<Text text="Text"/>
|
35
|
+
<ImageView>
|
36
|
+
<image>
|
37
|
+
<Image url="https://teratail-v2.storage.googleapis.com/uploads/avatars/u13/132786/KnkDDC5A_thumbnail.jpg"/>
|
38
|
+
</image>
|
39
|
+
</ImageView>
|
40
|
+
</children>
|
41
|
+
</VBox>
|
42
|
+
</content>
|
43
|
+
</ScrollPane>
|
44
|
+
</center>
|
45
|
+
</BorderPane>
|
46
|
+
```
|
47
|
+
|
48
|
+
```Java
|
49
|
+
package sample;
|
50
|
+
|
51
|
+
import javafx.event.ActionEvent;
|
52
|
+
import javafx.fxml.FXML;
|
53
|
+
import javafx.scene.image.Image;
|
54
|
+
import javafx.scene.image.ImageView;
|
55
|
+
import javafx.scene.layout.VBox;
|
56
|
+
import javafx.scene.text.Text;
|
57
|
+
|
58
|
+
public class Controller {
|
59
|
+
private static final String url1 = "https://teratail-v2.storage.googleapis.com/uploads/avatars/u17/171983/5c373ecbfa1165eb_thumbnail.jpeg";
|
60
|
+
private static final String url2 = "https://teratail-v2.storage.googleapis.com/uploads/avatars/u13/132786/KnkDDC5A_thumbnail.jpg";
|
61
|
+
|
62
|
+
@FXML
|
63
|
+
private VBox vbox;
|
64
|
+
|
65
|
+
@FXML
|
66
|
+
void onButton(ActionEvent event) {
|
67
|
+
vbox.getChildren().add(new ImageView(new Image(url1)));
|
68
|
+
vbox.getChildren().add(new Text("Text"));
|
69
|
+
vbox.getChildren().add(new ImageView(new Image(url2)));
|
70
|
+
}
|
71
|
+
}
|
72
|
+
```
|
73
|
+
|
74
|
+
```Java
|
75
|
+
package sample;
|
76
|
+
|
77
|
+
import javafx.application.Application;
|
78
|
+
import javafx.fxml.FXMLLoader;
|
79
|
+
import javafx.scene.Parent;
|
80
|
+
import javafx.scene.Scene;
|
81
|
+
import javafx.stage.Stage;
|
82
|
+
|
83
|
+
public class Main extends Application {
|
84
|
+
@Override
|
85
|
+
public void start(Stage primaryStage) throws Exception {
|
86
|
+
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
|
87
|
+
primaryStage.setScene(new Scene(root, 300, 275));
|
88
|
+
primaryStage.show();
|
89
|
+
}
|
90
|
+
|
91
|
+
public static void main(String[] args) {
|
92
|
+
launch(args);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
```
|
96
|
+

|
97
|
+
|
98
|
+
---
|
99
|
+
|
100
|
+
> 調べてみたところ、
|
101
|
+
|
102
|
+
調べたことを具体的に提示してください(見たURLや、自分で試したコード等)
|
103
|
+
「調べましたが」だけでは、第3者には全く伝わりません。
|
104
|
+
|
105
|
+
まだ読んでいなければこちらを一通り目を通してください。
|
106
106
|
[質問するときのヒント|teratail(テラテイル)](https://teratail.com/help/question-tips)
|