質問編集履歴
2
ダイアログにコンポーネントの配置記載がなかったので追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -89,10 +89,15 @@
|
|
89
89
|
private JProgressBar jProgressBar1 = new JProgressBar();
|
90
90
|
private int progressMinimum;
|
91
91
|
private int progressMaximum;
|
92
|
+
private JPanel = panel1 = new JPanel ();
|
92
93
|
|
93
94
|
/** コンストラクタ*/
|
94
95
|
public ProgDlgClass( Frame owner, boolean modal ) {
|
95
96
|
super( owner, modal );
|
97
|
+
jProgressBar1.setStringPainted(true);
|
98
|
+
panel1 .add(jProgressBar1);
|
99
|
+
jProgressBar1.setBounds(10, 10, 220, 30);
|
100
|
+
this.getContentPane().add(panel1 , java.awt.BorderLayout.CENTER);
|
96
101
|
this.setPreferredSize( new Dimension( 245, 140 ) );
|
97
102
|
}
|
98
103
|
|
1
ソースコード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,21 +8,149 @@
|
|
8
8
|
また、回避する方法はありますか。
|
9
9
|
javaは、1.6です。
|
10
10
|
|
11
|
+
以下実装ソースです。実際、とても長いので省略します。
|
12
|
+
|
13
|
+
UserClass : 印刷処理を利用するクラス
|
14
|
+
PrintClass : 印刷処理を行うクラス
|
15
|
+
ProgDlgClass:進捗管理ダイアログクラス
|
16
|
+
|
11
17
|
```java
|
18
|
+
/** 印刷処理を利用するクラス */
|
19
|
+
class UserClass extend JFrame {
|
20
|
+
/** 印刷処理 */
|
21
|
+
private void PrintProc ( ){
|
22
|
+
PrintClass printCl = new PrintClass();
|
23
|
+
printCl.executePrint( this );
|
24
|
+
}
|
25
|
+
|
26
|
+
}
|
27
|
+
/** 印刷処理を行うクラス */
|
28
|
+
class PrintClass {
|
29
|
+
|
30
|
+
JFrame frame;
|
31
|
+
ProgDlgClass dialog;
|
32
|
+
/** 印刷処理 */
|
33
|
+
public void executePrint( JFrame frame ) {
|
34
|
+
|
35
|
+
dialog = new ProgDlgClass( frame, false );// モーダル false
|
36
|
+
|
37
|
+
dialog.setProgressMaximum( 0 );
|
38
|
+
dialog.setProgressMaximum( 0 );
|
39
|
+
dialog.setProgressValue( dialog.getProgressMinimum() );//最小値をセット
|
40
|
+
dialog.setProgressAuto( true ); // 最初は不確定モード
|
41
|
+
|
12
|
-
|
42
|
+
// 進捗表示のスレッド
|
13
|
-
|
43
|
+
Thread thread = new Thread( new Runnable() {
|
14
|
-
|
44
|
+
@Override
|
15
|
-
|
45
|
+
public void run() {
|
16
|
-
|
46
|
+
try {
|
17
|
-
|
47
|
+
dialog.execute();
|
48
|
+
}
|
49
|
+
catch ( Exception e ) {
|
50
|
+
//ここで例外ログ表示
|
51
|
+
}
|
52
|
+
} );
|
53
|
+
thread.start();
|
54
|
+
displayWaiting();
|
55
|
+
|
56
|
+
// 印刷処理実行スレッド
|
57
|
+
Thread thread2 = new Thread( new Runnable() {
|
58
|
+
public void run() {
|
59
|
+
executePrint();
|
18
60
|
}
|
61
|
+
} );
|
19
|
-
|
62
|
+
thread2.start();
|
63
|
+
|
64
|
+
}
|
65
|
+
|
20
|
-
|
66
|
+
/** 進捗画面の表示待ち */
|
67
|
+
private void displayWaiting() throws Exception {
|
68
|
+
for ( short i = 0; i < 300; i++ ) {
|
69
|
+
if ( dialog != null && dialog.isVisible() ) {
|
70
|
+
Thread.sleep( 100 );
|
71
|
+
return;
|
21
72
|
}
|
22
|
-
} );
|
23
|
-
|
73
|
+
Thread.sleep( 10 );
|
74
|
+
}
|
75
|
+
}
|
76
|
+
/** 印刷データ作成 */
|
77
|
+
private void executePrint() {
|
78
|
+
for( int i = 0 ; i < ・・・ ) {
|
79
|
+
dialog.setProgressValue( i );
|
80
|
+
//印刷データ作成 こちらで、プログレスバーの値を設定し、進捗状況を管理
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
}
|
85
|
+
|
86
|
+
/** 進捗管理 */
|
87
|
+
public class ProgDlgClass extends JDaialg {
|
88
|
+
|
89
|
+
private JProgressBar jProgressBar1 = new JProgressBar();
|
90
|
+
private int progressMinimum;
|
91
|
+
private int progressMaximum;
|
92
|
+
|
93
|
+
/** コンストラクタ*/
|
94
|
+
public ProgDlgClass( Frame owner, boolean modal ) {
|
95
|
+
super( owner, modal );
|
96
|
+
this.setPreferredSize( new Dimension( 245, 140 ) );
|
97
|
+
}
|
98
|
+
|
99
|
+
/**
|
100
|
+
* 開始
|
101
|
+
*/
|
102
|
+
public void execute() throws Exception {
|
103
|
+
if ( this.progressMaximum == 0 &&
|
104
|
+
this.progressMinimum == 0 &&
|
105
|
+
this.progressAuto == false ) {
|
106
|
+
// ここは、progressAuto = trueのため、今回は通らない
|
107
|
+
return;
|
108
|
+
}
|
109
|
+
this.setVisible( true );
|
110
|
+
}
|
111
|
+
|
112
|
+
/**プログレスバーの最大値設定 */
|
113
|
+
public void setProgressMaximum( int wkValue ) {
|
114
|
+
this.progressMaximum = wkValue;
|
115
|
+
this.jProgressBar1.setMaximum( wkValue );
|
116
|
+
}
|
117
|
+
|
118
|
+
/** プログレスバーの最小値設定*/
|
119
|
+
public void setProgressMinimum( int wkValue ) {
|
120
|
+
this.progressMinimum = wkValue;
|
121
|
+
this.jProgressBar1.setMinimum( wkValue );
|
122
|
+
}
|
123
|
+
|
124
|
+
/** プログレスバーの最小値設定*/
|
125
|
+
public int getProgressMinimum() {
|
126
|
+
return this.progressMinimum = wkValue;
|
127
|
+
}
|
128
|
+
|
129
|
+
/** プログレスバーの最小値設定*/
|
130
|
+
public int getProgressMinimum() {
|
131
|
+
return this.progressMinimum = wkValue;
|
132
|
+
}
|
133
|
+
|
134
|
+
/** プログレスバーの現在値を設定
|
135
|
+
* @param wkValue 設定しようとするプログレスバーの現在値
|
136
|
+
*/
|
137
|
+
public void setProgressValue( int wkValue ) {
|
138
|
+
this.jProgressBar1.setValue( wkValue );
|
139
|
+
}
|
140
|
+
|
141
|
+
/** プログレスバーの自動処理状態を設定します。
|
142
|
+
* @param wkBool 自動処理状態 true:勝手に動作します。
|
143
|
+
*/
|
144
|
+
public void setProgressAuto( boolean wkBool ) {
|
145
|
+
this.progressAuto = wkBool;
|
146
|
+
this.jProgressBar1.setIndeterminate( this.progressAuto );
|
147
|
+
this.jProgressBar1.setStringPainted( !this.progressAuto );
|
148
|
+
}
|
149
|
+
}
|
24
150
|
```
|
25
151
|
|
152
|
+
PrintClass の executePrintがexecuteされ、ProgDlgClass が表示された時に例外が発生。
|
153
|
+
終了は別途ボタンが有り、ボタン押下でdispose()が実行されます。
|
26
154
|
|
27
155
|
以下 例外内容
|
28
156
|
java.lang.IndexOutOfBoundsException: Index: 2, Size: 2
|