Skip to content

Commit 86657b9

Browse files
authored
Merge pull request #19 from SidaDan/master
Set Find class relative to jTextarea and 2 bug fixed (clases Find and About)
2 parents 62c6d8e + 0604421 commit 86657b9

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/simplejavatexteditor/About.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,22 @@
1414
* @modifiedby Achintha Gunasekara
1515
* @modweb http://www.achinthagunasekara.com
1616
* @modemail [email protected]
17+
*
18+
* @Modifiedby SidaDan
19+
* @modemail [email protected]
20+
* Bug fixed. If JTextArea txt not empty and the user will
21+
* shutdown the Simple Java NotePad, then the Simple Java NotePad
22+
* is only hidden (still running). So I added a WindowListener
23+
* an call method dispose() for this frame.
24+
* Tested with java 8.
1725
*/
1826

1927
package simplejavatexteditor;
2028

2129
import javax.swing.*;
2230
import java.awt.FlowLayout;
31+
import java.awt.event.WindowAdapter;
32+
import java.awt.event.WindowEvent;
2333

2434
public class About {
2535

@@ -32,6 +42,15 @@ public About(UI ui) {
3242
panel = new JPanel(new FlowLayout());
3343
panel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
3444
frame = new JFrame();
45+
46+
frame.addWindowListener(new WindowAdapter() {
47+
@Override
48+
public void windowClosing(WindowEvent e) {
49+
frame.dispose();
50+
}
51+
});
52+
53+
3554
frame.setVisible(true);
3655
frame.setSize(500,300);
3756
frame.setLocationRelativeTo(ui);

src/simplejavatexteditor/Find.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
* @modifiedby Achintha Gunasekara
1515
* @modweb http://www.achinthagunasekara.com
1616
* @modemail [email protected]
17+
*
18+
* @Modifiedby SidaDan
19+
* @modemail [email protected]
20+
* Center this JFrame to the JTextArea
21+
* Bug fixed. If JTextArea txt not empty and the user will
22+
* shutdown the Simple Java NotePad, then the Simple Java NotePad
23+
* is only hidden (still running). We need DISPOSE_ON_CLOSE for
24+
* this JFrame.
25+
* Tested with java 8.
1726
*/
1827

1928
package simplejavatexteditor;
@@ -94,11 +103,10 @@ public Find(JTextArea text) {
94103
// Set size window
95104
setSize(width,height);
96105

97-
// Set window position
98-
Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
99-
setLocation(center.x-width/2, center.y-height/2);
106+
// center the frame on the frame
107+
setLocationRelativeTo(txt);
100108
setVisible(true);
101-
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
109+
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
102110
}
103111

104112
public void find() {

0 commit comments

Comments
 (0)