4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /* @test
25 @bug 6866751
26 @summary J2SE_Swing_Reg: the caret disappears when moving to the end of the line.
27 @author Semyon Sadetsky
28 */
29 import javax.swing.*;
30 import java.awt.*;
31
32 public class bug6866751 {
33 private static JFrame frame;
34 private static JTextArea area;
35
36 public static void main(String[] args) throws Exception {
37 try {
38 SwingUtilities.invokeAndWait(new Runnable() {
39 public void run() {
40 frame = new JFrame();
41 frame.setUndecorated(true);
42 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
43 setup(frame);
44 }
45 });
46 SwingUtilities.invokeAndWait(new Runnable() {
47 public void run() {
48 int width = area.getWidth();
60 });
61 new Robot().waitForIdle();
62 SwingUtilities.invokeAndWait(new Runnable() {
63 public void run() {
64 int width = area.getWidth();
65 double caretX =
66 area.getCaret().getMagicCaretPosition().getX();
67 if (width < caretX + 10) {
68 throw new RuntimeException(
69 "Width of the area (" + width +
70 ") is less than caret x-position " +
71 caretX + 10);
72 }
73 }
74 });
75 System.out.println("ok");
76 } finally {
77 SwingUtilities.invokeAndWait(new Runnable() {
78 @Override
79 public void run() {
80 frame.dispose();
81 }
82 });
83 }
84 }
85
86 static void setup(JFrame frame) {
87 area = new JTextArea();
88 frame.getContentPane().add(new JScrollPane(area));
89 area.setText(
90 "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm");
91 area.getCaret().setDot(area.getText().length() + 1);
92
93 frame.setSize(300, 200);
94 frame.setVisible(true);
95
96 area.requestFocus();
97
98 }
99
100 }
|
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 * @test
26 * @key headful
27 * @bug 6866751
28 * @summary J2SE_Swing_Reg: the caret disappears when moving to the end of the line.
29 * @author Semyon Sadetsky
30 */
31
32 import javax.swing.*;
33 import java.awt.*;
34
35 public class bug6866751 {
36 private static JFrame frame;
37 private static JTextArea area;
38
39 public static void main(String[] args) throws Exception {
40 try {
41 SwingUtilities.invokeAndWait(new Runnable() {
42 public void run() {
43 frame = new JFrame();
44 frame.setUndecorated(true);
45 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
46 setup(frame);
47 }
48 });
49 SwingUtilities.invokeAndWait(new Runnable() {
50 public void run() {
51 int width = area.getWidth();
63 });
64 new Robot().waitForIdle();
65 SwingUtilities.invokeAndWait(new Runnable() {
66 public void run() {
67 int width = area.getWidth();
68 double caretX =
69 area.getCaret().getMagicCaretPosition().getX();
70 if (width < caretX + 10) {
71 throw new RuntimeException(
72 "Width of the area (" + width +
73 ") is less than caret x-position " +
74 caretX + 10);
75 }
76 }
77 });
78 System.out.println("ok");
79 } finally {
80 SwingUtilities.invokeAndWait(new Runnable() {
81 @Override
82 public void run() {
83 if (frame != null) { frame.dispose(); }
84 }
85 });
86 }
87 }
88
89 static void setup(JFrame frame) {
90 area = new JTextArea();
91 frame.getContentPane().add(new JScrollPane(area));
92 area.setText(
93 "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm");
94 area.getCaret().setDot(area.getText().length() + 1);
95
96 frame.setSize(300, 200);
97 frame.setVisible(true);
98
99 area.requestFocus();
100
101 }
102
103 }
|