質問するログイン新規登録

質問編集履歴

2

記載ミス修正

2017/03/09 04:54

投稿

katare
katare

スコア15

title CHANGED
File without changes
body CHANGED
@@ -6,177 +6,172 @@
6
6
 
7
7
  ```JavaFX
8
8
  // CombBoxクラス
9
- public class CmbSyainID {
9
+ public class cmbSyainID {
10
- private final SimpleIntegerProperty iSyainID = new SimpleIntegerProperty();
10
+ private final SimpleIntegerProperty iSyainID = new SimpleIntegerProperty();
11
- private final SimpleStringProperty sSyainName = new SimpleStringProperty();
11
+ private final SimpleStringProperty sSyainName = new SimpleStringProperty();
12
12
 
13
- public CmbSyainID () {
13
+ public cmbSyainID() {
14
- this (0,"");
14
+ this (0,"");
15
- }
15
+ }
16
- public CmbSyainID (Integer id, String name) {
16
+ public cmbSyainID (Integer id, String name) {
17
- setSyainID(id);
17
+ setSyainID(id);
18
- setSyainName(name);
18
+ setSyainName(name);
19
- }
19
+ }
20
20
  // ―――――――――――――――――――――――――――――――――――――――――――――――――――――
21
- public Integer getSyainID() {
21
+ public Integer getSyainID() {
22
- return iSyainID.get();
22
+ return iSyainID.get();
23
- }
23
+ }
24
- public void setSyainID(Integer id){
24
+ public void setSyainID(Integer id){
25
- iSyainID.set(id);
25
+ iSyainID.set(id);
26
- }
26
+ }
27
- public String getSyainName() {
27
+ public String getSyainName() {
28
- return sSyainName.get();
28
+ return sSyainName.get();
29
- }
29
+ }
30
- public void setSyainName(String name) {
30
+ public void setSyainName(String name) {
31
- sSyainName.set(name);
31
+ sSyainName.set(name);
32
- }
32
+ }
33
- public void setSelectedItem(Integer syubetsuid) {
33
+ public void setSelectedItem(Integer id) {
34
- iSyubetsuID.set(syubetsuid);
34
+ iSyainID.set(id);
35
- }
35
+ }
36
- public Integer getSelectedItem() {
36
+ public Integer getSelectedItem() {
37
- return iSyubetsuID.get();
37
+ return iSyainID.get();
38
- }
38
+ }
39
39
  // ―――――――――――――――――――――――――――――――――――――――――――――――――――――
40
- public int getValue() {
40
+ public int getValue() {
41
- return iSyainID.get();
41
+ return iSyainID.get();
42
- }
43
- public void setValue(Integer id) {
44
- iSyainID.set(id);
45
- }
46
- public String getText() {
47
- return sSyainName.get();
48
- }
49
- public void setText(String name) {
50
- sSyainName.set(name);
51
- }
52
- public String toString() {
53
- return sSyainName.get();
54
- }
55
42
  }
56
-
43
+ public void setValue(Integer id) {
44
+ iSyainID.set(id);
45
+ }
46
+ public String getText() {
47
+ return sSyainName.get();
48
+ }
49
+ public void setText(String name) {
50
+ sSyainName.set(name);
51
+ }
52
+ public String toString() {
53
+ return sSyainName.get();
54
+ }
55
+ }
57
56
  // Controllerクラス
58
- public class SyainController implements Initializable {
57
+ public class SyainController implements Initializable {
59
- @FXML ComboBox<CmbSyainID> cSyainID;
58
+ @FXML ComboBox<cmbSyainID> cSyainID;
60
- @FXML TableView<LstSyain> LstSyain;
59
+ @FXML TableView<LstSyain> LstSyain;
60
+ @FXML TextField tSyainName;
61
+
62
+ Integer iBusyoID = 10;
63
+ PreparedStatement pstmt = null;
64
+ ResultSet rset = null;
61
65
 
66
+ @Override
67
+ public void initialize(URL url , ResourceBundle rb) {
68
+ // * CombBox List
69
+ // ―――――――――――――――――――――――――――――――――――――――――――――――――――――
70
+ setSyainList();
62
- PreparedStatement pstmt = null;
71
+ cSyainID.getSelectionModel().select(0);
72
+
63
- ResultSet rset = null;
73
+ // * TableView List
74
+ // ―――――――――――――――――――――――――――――――――――――――――――――――――――――
75
+ LstSyain.getItems().setAll(returnSyainList());
64
76
 
77
+ LstSyain.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<LstSyain> () {
65
78
  @Override
66
- public void initialize(URL url , ResourceBundle rb) {
67
- // * CombBox List
68
- // ―――――――――――――――――――――――――――――――――――――――――――――――――――――
69
- setSyainList();
70
- cSyainID.getSelectionModel().select(0);
71
-
72
- // * TableView List
73
- // ―――――――――――――――――――――――――――――――――――――――――――――――――――――
74
- Lstsyain.getItems().setAll(returnSyainList());
75
-
76
- Lstsyain.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<LstSyain> () {
77
- @Override
78
- public void changed(ObservableValue<? extends LstSyain> value, LstSyain oldValue, LstSyain newValue) {
79
+ public void changed(ObservableValue<? extends LstSyain> value, LstSyain oldValue, LstSyain newValue) {
79
- if (LstSyain.getSelectionModel().getSelectedItem() != null) {
80
+ if (LstSyain.getSelectionModel().getSelectedItem() != null) {
80
- //getSyainName()は、LstSyainクラスにて宣言
81
+ //getSyainName()は、LstSyainクラスにて宣言
81
- tSyainName.setText((String) newValue.getSyainName());
82
+ tSyainName.setText((String) newValue.getSyainName());
82
- // ※※※※※※※※※※※※※※※※※※※※※※※※※※※
83
+ // ※※※※※※※※※※※※※※※※※※※※※※※※※※※
83
- //Listの動きに伴って、CombBoxの値も変更したい
84
+ //Listの動きに伴って、CombBoxの値も変更したい
84
- //今回指摘して頂いた ⇒ select(T item) (B)選択すべきアイテムのvalueを指定をしてるつもり
85
+ //今回指摘して頂いた ⇒ select(T item) (B)選択すべきアイテムのvalueを指定をしてるつもり
85
- cSyainID.getSelectionModel().select(newValue.getSyainID());
86
+ cSyainID.getSelectionModel().select(newValue.getSyainID());
86
- // ※※※※※※※※※※※※※※※※※※※※※※※※※※※
87
+ // ※※※※※※※※※※※※※※※※※※※※※※※※※※※
87
- }
88
88
  }
89
+ }
89
- });
90
+ });
90
- }
91
+ }
92
+ // * CombBox List.
93
+ //──────────────────────────────
94
+ public void setSyainList() {
95
+ String strSQL = "Execute dbo.PStad"
96
+ + " @NN = 'CBoxSource'"
97
+ + ", @BusyoID = " + Integer.toString(iBusyoID);
91
98
 
92
- // * CombBox List.
93
- //──────────────────────────────
94
- public void setSyainList() {
95
- String strSQL = "Execute dbo.PStad"
96
- + " @NN = 'CBoxSource'"
97
- + ", @BusyoID = " + Integer.toString(iBusyoID);
98
-
99
- PreparedStatement pstmt = null;
99
+ PreparedStatement pstmt = null;
100
- ResultSet rset = null;
100
+ ResultSet rset = null;
101
-
102
- List<CmbSyainID> ll = new LinkedList<CmbSyainID>();
103
- CmbSyainID roww = new CmbSyainID();
104
-
105
- // ──────────────────────────────
106
- try {
107
- Connection con = DBConnect.connect(); //DBConnec Connectionクラス
108
- pstmt = con.prepareStatement(strSQL);
109
- rset = pstmt.executeQuery();
110
101
 
102
+ List<cmbSyainID> ll = new LinkedList<cmbSyainID>();
103
+ cmbSyainID roww = new cmbSyainID();
104
+
105
+ // ──────────────────────────────
106
+ try {
107
+ Connection con = DBConnect.connect(); //DBConnec Connectionクラス
108
+ pstmt = con.prepareStatement(strSQL);
109
+ rset = pstmt.executeQuery();
110
+
111
- while (rset.next()) {
111
+ while (rset.next()) {
112
- roww = new CmbSyubetsuID();
112
+ roww = new cmbSyainID();
113
- roww.setSyainID(rset.getInt(1));
113
+ roww.setSyainID(rset.getInt(1));
114
- roww.setSyainName(rset.getString(2));
114
+ roww.setSyainName(rset.getString(2));
115
- ll.add(roww);
115
+ ll.add(roww);
116
+ }
117
+ rset.close();
118
+ pstmt.close();
119
+ } catch (Exception e) {
120
+ e.printStackTrace();
116
121
  }
117
- rset.close();
118
- pstmt.close();
119
- } catch (Exception e) {
120
- e.printStackTrace();
122
+ cSyainID.getItems().setAll(ll);
121
123
  }
122
- cSyainID.getItems().setAll(ll);
123
- }
124
124
 
125
- // * TableView List.
125
+ // * TableView List.
126
- //──────────────────────────────
126
+ //──────────────────────────────
127
- private List<Lstsyain> returnSyainList() {
127
+ private List<LstSyain> returnSyainList() {
128
- Integer iID = 100;
128
+ Integer iID = 100;
129
129
 
130
- PreparedStatement pstmt = null;
130
+ PreparedStatement pstmt = null;
131
- ResultSet rset = null;
131
+ ResultSet rset = null;
132
- List<LstTableView> ll = new LinkedList<LstTableView>();
132
+ List<LstSyain> ll = new LinkedList<LstSyain>();
133
133
 
134
- // ※初期化
134
+ try {
135
- Lstsyain.setPlaceholder(new Label("表示する内容はありません。"));
136
- tSyainName.setText("");
137
- cSyainID.getSelectionModel().select(null);
135
+ Connection cnn = DBConnect.connect();
136
+ String strSQL = "Execute dbo.PStad"
137
+ + " @nn = 'ListReturn'"
138
+ + ", @ID = " + Integer.toString(iID);
138
139
 
140
+ pstmt = cnn.prepareStatement(strSQL);
141
+ rset = pstmt.executeQuery();
142
+
139
- try {
143
+ int i = 0;
144
+ while (rset.next()) {
145
+ i = i + 1;
146
+ //──────────────────────────────
140
- Connection cnn = DBConnect.connect();
147
+ Integer id = rset.getInt(1);
141
- String strSQL = "Execute dbo.PStad"
148
+ String name = rset.getString(2);
142
- + " @nn = 'ListReturn'"
143
- + ", @ID = " + Integer.toString(iID);
144
149
 
150
+ //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
145
- pstmt = cnn.prepareStatement(strSQL);
151
+ // 一番上のレコードの値ををコントロールに表示
146
- rset = pstmt.executeQuery();
147
-
148
- int i = 0;
152
+ if (i == 1) {
153
+ //※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
149
- while (rset.next()) {
154
+ // select(i) indexではなくValueでSelectしたい
150
- i = i + 1;
151
- //──────────────────────────────
155
+ // cmbCombBox.select(T item)
152
- Integer id = rset.getInt(1);
156
+ cSyainID.getSelectionModel().select(id);
157
+ //※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
153
- String name = rset.getString(2);
158
+ tSyainName.setText(name);
159
+ }
160
+ //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
154
161
 
155
- //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
156
- // 一番上のレコードの値ををコントロールに表示
162
+ LstSyain roww = new LstSyain();
157
- if (i == 1) {
158
- tfName.setText(nama);
163
+ roww.setSyainID(id);
159
- //※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
160
- // select(i) indexではなくValueでSelectしたい
161
- // cmbCombBox.select(T item)
162
- cSyainID.getSelectionModel().select(id);
163
- //※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
164
- tSyainName.setText(name);
164
+ roww.setSyainName(name);
165
+
166
+ ll.add(roww);
165
167
  }
166
- //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
167
-
168
- LstTableViewroww = new LstTableView();
169
- roww.setID(id);
168
+ rset.close();
170
- roww.setName(nama);
171
-
172
- ll.add(roww);
169
+ pstmt.close();
173
170
  }
174
- rset.close();
171
+ catch (Exception e) {
175
- pstmt.close();
172
+ e.printStackTrace();
173
+ }
174
+ return ll;
176
175
  }
177
- catch (Exception e) {
178
- e.printStackTrace();
179
- }
176
+ }
180
- return ll;
181
- }
182
177
  ```

1

CombBoxのクラス追記および、CombBoxの値を変更したい箇所を追加

2017/03/09 04:54

投稿

katare
katare

スコア15

title CHANGED
File without changes
body CHANGED
@@ -5,26 +5,142 @@
5
5
  開発環境は、Luna 4.4.2です。
6
6
 
7
7
  ```JavaFX
8
+ // CombBoxクラス
9
+ public class CmbSyainID {
10
+ private final SimpleIntegerProperty iSyainID = new SimpleIntegerProperty();
11
+ private final SimpleStringProperty sSyainName = new SimpleStringProperty();
12
+
13
+ public CmbSyainID () {
14
+ this (0,"");
15
+ }
16
+ public CmbSyainID (Integer id, String name) {
17
+ setSyainID(id);
18
+ setSyainName(name);
19
+ }
20
+ // ―――――――――――――――――――――――――――――――――――――――――――――――――――――
21
+ public Integer getSyainID() {
22
+ return iSyainID.get();
23
+ }
24
+ public void setSyainID(Integer id){
25
+ iSyainID.set(id);
26
+ }
27
+ public String getSyainName() {
28
+ return sSyainName.get();
29
+ }
30
+ public void setSyainName(String name) {
31
+ sSyainName.set(name);
32
+ }
33
+ public void setSelectedItem(Integer syubetsuid) {
34
+ iSyubetsuID.set(syubetsuid);
35
+ }
36
+ public Integer getSelectedItem() {
37
+ return iSyubetsuID.get();
38
+ }
39
+ // ―――――――――――――――――――――――――――――――――――――――――――――――――――――
40
+ public int getValue() {
41
+ return iSyainID.get();
42
+ }
43
+ public void setValue(Integer id) {
44
+ iSyainID.set(id);
45
+ }
46
+ public String getText() {
47
+ return sSyainName.get();
48
+ }
49
+ public void setText(String name) {
50
+ sSyainName.set(name);
51
+ }
52
+ public String toString() {
53
+ return sSyainName.get();
54
+ }
55
+ }
56
+
57
+ // Controllerクラス
58
+ public class SyainController implements Initializable {
59
+ @FXML ComboBox<CmbSyainID> cSyainID;
60
+ @FXML TableView<LstSyain> LstSyain;
61
+
62
+ PreparedStatement pstmt = null;
63
+ ResultSet rset = null;
64
+
65
+ @Override
66
+ public void initialize(URL url , ResourceBundle rb) {
67
+ // * CombBox List
68
+ // ―――――――――――――――――――――――――――――――――――――――――――――――――――――
69
+ setSyainList();
70
+ cSyainID.getSelectionModel().select(0);
71
+
72
+ // * TableView List
73
+ // ―――――――――――――――――――――――――――――――――――――――――――――――――――――
74
+ Lstsyain.getItems().setAll(returnSyainList());
75
+
76
+ Lstsyain.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<LstSyain> () {
77
+ @Override
78
+ public void changed(ObservableValue<? extends LstSyain> value, LstSyain oldValue, LstSyain newValue) {
79
+ if (LstSyain.getSelectionModel().getSelectedItem() != null) {
80
+ //getSyainName()は、LstSyainクラスにて宣言
81
+ tSyainName.setText((String) newValue.getSyainName());
82
+ // ※※※※※※※※※※※※※※※※※※※※※※※※※※※
83
+ //Listの動きに伴って、CombBoxの値も変更したい
84
+ //今回指摘して頂いた ⇒ select(T item) (B)選択すべきアイテムのvalueを指定をしてるつもり
85
+ cSyainID.getSelectionModel().select(newValue.getSyainID());
86
+ // ※※※※※※※※※※※※※※※※※※※※※※※※※※※
87
+ }
88
+ }
89
+ });
90
+ }
91
+
92
+ // * CombBox List.
93
+ //──────────────────────────────
94
+ public void setSyainList() {
95
+ String strSQL = "Execute dbo.PStad"
96
+ + " @NN = 'CBoxSource'"
97
+ + ", @BusyoID = " + Integer.toString(iBusyoID);
98
+
99
+ PreparedStatement pstmt = null;
100
+ ResultSet rset = null;
101
+
102
+ List<CmbSyainID> ll = new LinkedList<CmbSyainID>();
103
+ CmbSyainID roww = new CmbSyainID();
104
+
105
+ // ──────────────────────────────
106
+ try {
107
+ Connection con = DBConnect.connect(); //DBConnec Connectionクラス
108
+ pstmt = con.prepareStatement(strSQL);
109
+ rset = pstmt.executeQuery();
110
+
111
+ while (rset.next()) {
112
+ roww = new CmbSyubetsuID();
113
+ roww.setSyainID(rset.getInt(1));
114
+ roww.setSyainName(rset.getString(2));
115
+ ll.add(roww);
116
+ }
117
+ rset.close();
118
+ pstmt.close();
119
+ } catch (Exception e) {
120
+ e.printStackTrace();
121
+ }
122
+ cSyainID.getItems().setAll(ll);
123
+ }
124
+
125
+ // * TableView List.
126
+ //──────────────────────────────
8
- private List<LstTableView> returnTableView() {
127
+ private List<Lstsyain> returnSyainList() {
9
128
  Integer iID = 100;
10
- String sDate = "2017/03/10";
11
129
 
12
130
  PreparedStatement pstmt = null;
13
131
  ResultSet rset = null;
14
132
  List<LstTableView> ll = new LinkedList<LstTableView>();
15
133
 
16
134
  // ※初期化
17
- LstTableView.setPlaceholder(new Label("表示する内容はありません。"));
135
+ Lstsyain.setPlaceholder(new Label("表示する内容はありません。"));
18
- tfName.setText("");
136
+ tSyainName.setText("");
19
- cmbCombBox.getSelectionModel().select(null);
137
+ cSyainID.getSelectionModel().select(null);
20
- dtfDay.setValue(DateTimes.toLocalDate(""));
21
138
 
22
- try {
139
+ try {
23
140
  Connection cnn = DBConnect.connect();
24
- String strSQL = "Execute dbo.PStad"
141
+ String strSQL = "Execute dbo.PStad"
25
- + " @nn = 'LIstreturn'"
142
+ + " @nn = 'ListReturn'"
26
- + ", @ID = " + Integer.toString(iID)
143
+ + ", @ID = " + Integer.toString(iID);
27
- + ", @Date = '" + sDate + "'";
28
144
 
29
145
  pstmt = cnn.prepareStatement(strSQL);
30
146
  rset = pstmt.executeQuery();
@@ -32,32 +148,26 @@
32
148
  int i = 0;
33
149
  while (rset.next()) {
34
150
  i = i + 1;
35
- // ──────────────────────────────
151
+ //──────────────────────────────
36
152
  Integer id = rset.getInt(1);
37
- String nama = rset.getString(2);
153
+ String name = rset.getString(2);
38
- Integer nameid = rset.getInt(3);
39
- String date = rset.getString(4);
40
154
 
41
155
  //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
156
+ // 一番上のレコードの値ををコントロールに表示
42
157
  if (i == 1) {
43
158
  tfName.setText(nama);
44
-
45
159
  //※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
46
- // select(i) Row_Count()でなくValueでSelectしたい
160
+ // select(i) indexなくValueでSelectしたい
47
- // cmbCombBox.setSelectItem(nameid)な感じ
161
+ // cmbCombBox.select(T item)
48
- cmbCombBox.getSelectionModel().select(nameid);
162
+ cSyainID.getSelectionModel().select(id);
49
-
50
163
  //※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
51
-
52
- dtfKeiyakuDay.setValue(DateTimes.toLocalDate(date));
164
+ tSyainName.setText(name);
53
165
  }
54
166
  //━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
55
167
 
56
168
  LstTableViewroww = new LstTableView();
57
169
  roww.setID(id);
58
- roww.setDay(date);
59
170
  roww.setName(nama);
60
- roww.setNameID(nameid);
61
171
 
62
172
  ll.add(roww);
63
173
  }