Skip to content

Commit 2b086ad

Browse files
author
duke
committed
Backport 62c0a1b9ac6462233f3ee06af470be9844e9e226
1 parent bfc957a commit 2b086ad

File tree

4 files changed

+199
-0
lines changed

4 files changed

+199
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 4138694
26+
* @summary When adding an Action object to a toolbar, the Action object's
27+
* SHORT_DESCRIPTION property (if present) should be automatically used
28+
* for toolTip text.
29+
* @run main bug4138694
30+
*/
31+
32+
import java.awt.event.ActionEvent;
33+
34+
import javax.swing.AbstractAction;
35+
import javax.swing.Action;
36+
import javax.swing.JComponent;
37+
import javax.swing.JToolBar;
38+
import javax.swing.SwingUtilities;
39+
40+
public class bug4138694 {
41+
public static final String actionName = "Action";
42+
43+
private static class MyAction extends AbstractAction {
44+
public void actionPerformed(ActionEvent e) {}
45+
}
46+
47+
public static void main(String[] args) throws Exception {
48+
SwingUtilities.invokeAndWait(() -> {
49+
JToolBar jtb = new JToolBar();
50+
MyAction aa = new MyAction();
51+
aa.putValue(Action.SHORT_DESCRIPTION, actionName);
52+
jtb.add(aa);
53+
JComponent c = (JComponent)jtb.getComponentAtIndex(0);
54+
if (!c.getToolTipText().equals(actionName)) {
55+
throw new RuntimeException("ToolTip not set automatically...");
56+
}
57+
});
58+
}
59+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 4140421
26+
* @summary Tests JToolBar set title correctly
27+
* @run main bug4140421
28+
*/
29+
30+
import javax.swing.JToolBar;
31+
import javax.swing.SwingUtilities;
32+
33+
public class bug4140421 {
34+
public static void main(String[] args) throws Exception {
35+
SwingUtilities.invokeAndWait(() -> {
36+
JToolBar tb = new JToolBar("MyToolBar");
37+
if (!tb.getName().equals("MyToolBar")) {
38+
throw new RuntimeException("Title of JToolBar set incorrectly...");
39+
}
40+
});
41+
}
42+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 4196662
26+
* @summary JToolBar has remove(int) method.
27+
* @run main bug4196662
28+
*/
29+
30+
import javax.swing.JButton;
31+
import javax.swing.JToolBar;
32+
import javax.swing.SwingUtilities;
33+
34+
public class bug4196662 {
35+
public static void main(String[] args) throws Exception {
36+
SwingUtilities.invokeAndWait(() -> {
37+
JToolBar tb = new JToolBar();
38+
tb.add(new JButton("Button1"));
39+
JButton bt2 = new JButton("Button2");
40+
tb.add(bt2);
41+
tb.add(new JButton("Button3"));
42+
tb.remove(1);
43+
if (tb.getComponentCount() != 2 || tb.getComponent(1) == bt2) {
44+
throw new RuntimeException("Component wasn't removed...");
45+
}
46+
});
47+
}
48+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 1999, 2023, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 4243930
26+
* @summary Tests that JToolBar.remove() does not throw StackOverflowError
27+
* @run main bug4243930
28+
*/
29+
30+
import java.awt.event.ActionEvent;
31+
32+
import javax.swing.AbstractAction;
33+
import javax.swing.JButton;
34+
import javax.swing.JToolBar;
35+
import javax.swing.SwingUtilities;
36+
37+
public class bug4243930 {
38+
39+
private static class NullAction extends AbstractAction {
40+
public void actionPerformed(ActionEvent e){}
41+
}
42+
43+
public static void main(String[] args) throws Exception {
44+
SwingUtilities.invokeAndWait(() -> {
45+
JToolBar tb = new JToolBar();
46+
JButton test = tb.add(new NullAction());
47+
tb.remove(test);
48+
});
49+
}
50+
}

0 commit comments

Comments
 (0)