---
title: Swing Bugs
keywords: [Java, Swing]
description: Swing関連で注目しているバグIDへのリンク、メモなど
author: aterai
pubdate: 2018-01-22T16:28:08+09:00
---
* Summary [#summary]
[[Swing]]関係で個人的に注目しているバグ`ID`へのリンクなどをメモしています。
#contents
* 未修正 [#NotFixedYet]
** ComponentOrientation.RIGHT_TO_LEFTが設定されたJMenuBarの矢印キーによるフォーカス移動がおかしい [#a5eb1769]
- [https://stackoverflow.com/questions/69984888/jmenubar-arrow-keys-work-the-opposite-of-what-expected-because-componentorientat java - JMenuBar arrow keys work the opposite of what expected because componentOrientation is set to Right to Left - Stack Overflow]
-- [https://bugs.openjdk.org/browse/JDK-8277369 [JDK-8277369] Strange behavior of JMenuBar with RIGHT_TO_LEFT orientation, arrow keys behaves opposite traversing through keyboard - Java Bug System]
-- [https://github.com/openjdk/jdk/pull/7396 8277369: Strange behavior of JMenuBar with RIGHT_TO_LEFT orientation, arrow keys behaves opposite traversing through keyboard by prsadhuk · Pull Request #7396 · openjdk/jdk]で修正される
** JToolBarに配置したJButtonのフォーカス描画 [#w21ce2da]
- [https://stackoverflow.com/questions/37295099/decorating-a-rollover-toolbar-button-with-jlayer-paints-its-border#37295921 java - Decorating a rollover toolbar button with JLayer paints its border - Stack Overflow]
-- `JButton`を`JLayer`でラップして`JToolBar`に追加すると、`JToolBar`用のフォーカス描画ではなく、デフォルトのフォーカス描画が適用されてしまう
-- 回答されているように、`BasicToolBarUI#setBorderToRollover(...)`などが、`JLayer`を想定していない
-- [[JLayerで隣接する別コンポーネント上に縁を描画>Swing/OverlapBorderPaintLayer]]のように、親の`JToolBar`に`JLayer`を設定し、`e.getComponent()`で`JButton`を取得して回避可能
** NimbusLookAndFeelでのJComboBoxの推奨サイズ [#x115b70b]
- [https://stackoverflow.com/questions/36274053/swing-jcombobox-bug-printing-dimension java - Swing (JComboBox) bug? printing dimension - Stack Overflow]
-- `JComboBox`の時点と、`JFrame`に追加して`JFrame#pack()`もしくは`JFrame.setSize(...)`後で、`JComboBox`の推奨サイズ(幅)が異なる?
-- `NimbusLookAndFeel`のみの現象?
-- `setEditable(true)`にすると高さが異なる...
- `JComboBox#getPreferredSize()`を呼ぶと項目の文字列長を検索して、`cachedMinimumSize`にサイズがキャッシュされる
- `ArrowButton`の幅がデフォルト`16`と`JComboBox`用は`19`と異なる
- `SynthArrowButton#getPreferredSize(JComponent)`で、`context.getStyle().getInt(context, "ArrowButton.size", 16);`が呼ばれている
#code{{
import java.awt.*;
import javax.swing.*;
public class NimbusComboBoxSizeTest {
public JComponent makeUI() {
String[] model = {"Average"};
JPanel p0 = new JPanel();
JComboBox<String> combo0 = new JComboBox<>(model);
p0.add(combo0);
JPanel p1 = new JPanel();
JComboBox<String> combo1 = new JComboBox<>(model);
p1.add(combo1);
Box box = Box.createVerticalBox();
box.add(p0);
box.add(p1);
EventQueue.invokeLater(() -> System.out.println("combo0: " + combo0.getPreferredSize()));
System.out.println("combo1: " + combo1.getPreferredSize());
JPanel p = new JPanel(new BorderLayout());
p.add(box, BorderLayout.NORTH);
return p;
}
public static void main(String[] args) {
EventQueue.invokeLater(() -> createAndShowGUI());
}
public static void createAndShowGUI() {
try {
for (UIManager.LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(laf.getName())) {
UIManager.setLookAndFeel(laf.getClassName());
UIDefaults d = UIManager.getLookAndFeelDefaults();
System.out.println("ArrowButton.size: " + d.getInt("ArrowButton.size"));
System.out.println("ComboBox.arrowButton.size: " + d.getInt("ComboBox:\"ComboBox.arrowButton\".size"));
//どちらかのコメントを外して値を揃えてやると、以下の現象は修正される?
//d.put("ComboBox:\"ComboBox.arrowButton\".size", 16);
//d.put("ArrowButton.size", 19);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
JFrame f = new JFrame();
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.getContentPane().add(new NimbusComboBoxSizeTest().makeUI());
f.setSize(320, 240);
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
}}
** 高解像度でJOptionPaneのアイコンが欠ける [#vfc496a6]
- [https://stackoverflow.com/questions/30774828/bad-swing-ui-scaling-on-high-resolution-ms-surface java - Bad Swing UI scaling on high resolution (MS Surface) - Stack Overflow]
-- `Surface Pro 3`でテキスト文字サイズを`150%`に設定し、`JOptionPane`を`WindowsLookAndFeel`で表示すると、アイコンが欠けるバグ?
-- 以下のように`OptionPane.minimumSize`を設定しても解消しない
-- レイアウトでおかしくなっているのではなく、取得するアイコン自体が欠けている?
#code{{
import java.awt.*;
import javax.swing.*;
public class OptionPaneResolutionTest {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override public void run() {
createAndShowGUI();
}
});
}
public static void createAndShowGUI() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
Dimension defaultSize = UIManager.getDimension("OptionPane.minimumSize");
System.out.println("OptionPane.minimumSize default: " + defaultSize);
int sr = Toolkit.getDefaultToolkit().getScreenResolution();
float dpi = System.getProperty("os.name").startsWith("Windows") ? 96f : 72f;
float sot = sr / dpi;
System.out.format("%d%%%n", (int)(sot * 100));
Dimension mind = new Dimension((int)(defaultSize.width * sot),
(int)(defaultSize.height * sot));
System.out.println("OptionPane.minimumSize: " + mind);
UIManager.put("OptionPane.minimumSize", mind);
JOptionPane.showMessageDialog(null, "msg", "Information", JOptionPane.INFORMATION_MESSAGE);
}
}
}}
** MetalLookAndFeelでのJComboBoxとJToolTip [#fc4b2abf]
- ドロップダウンリストを開いた状態でツールチップが表示されると描画がおかしくなる場合がある
-- `MetalLookAndFeel`のみ
-- ドロップダウンリストが`HeavyWeightWindow`か`LightWeightWindow`かは無関係
- [[JComboBoxの各アイテムやArrowButtonにそれぞれToolTipTextを設定する>Swing/ToolTipInComboBox]]にソースコードは移動
#img2(https://drive.google.com/uc?id=1l662LOjb0AFVh6F9lOSm78ZsXzJfuG0GDQ)
* 修正済み [#Fixed]
** 1.8.0_212 からImageView#setLoadsSynchronously(...)の設定で画像がJEditorPaneに表示されない [#he9725ec]
- `JDK 11.0.2`、`JDK 8.0.202`から`ImageView`に`setLoadsSynchronously(true)`を設定すると画像が表示されなくなってしまった
- `JDK 11.0.1`、`JDK 8.0.202`では正常に画像が表示される
- `JDK 8.0.222`では修正されている
-- [[JEditorPaneに読み込んだHTMLを画像に変換する>Swing/LoadsSynchronously]]
-- [https://bugs.openjdk.org/browse/JDK-8223384 [JDK-8223384] ImageView incorrectly calculates size when synchronously loaded - Java Bug System]
-- `OracleJDK`でも`OpenJDK`でも同じ状況
- [https://bugs.openjdk.org/browse/JDK-8208638 [JDK-8208638] Instead of circle rendered in appl window, but ellipse is produced JEditor Pane - Java Bug System]のリグレッション?
** OpenJDK Corretto 1.8.0_212 で図形の描画が崩壊する [#wb9bc344]
- `Corretto 1.8.0_212`(`Windows 10`環境)でソフトクリッピング効果を使用すると描画がおかしくなる?
openjdk version "1.8.0_212"
OpenJDK Runtime Environment Corretto-8.212.04.2 (build 1.8.0_212-b04)
OpenJDK 64-Bit Server VM Corretto-8.212.04.2 (build 25.212-b04, mixed mode)
#img2(https://drive.google.com/uc?id=1UmzUcA-QK_mtJAYvjvDn5-qoud7PfOWO_Q)
- 以下もおそらく同原因
-- [[Windowの縁をソフトクリッピングでなめらかにする>Swing/SoftClippedWindow]]
-- [[JPanelに色相環を描画する>Swing/ColorWheel]]
-- [[JSpinnerの表記を16進数にする>Swing/HexFormatterSpinner]]
-- [[Fontを回転する>Swing/TransformedShape]]
- %%[https://docs.oracle.com/javase/jp/8/docs/technotes/guides/2d/flags.html Java 2Dテクノロジのシステム・プロパティ]などを変更して調査しているがまだ原因不明%%
-- 切り抜き図形の幅を`32`の倍数以外にすると発生しない(高さは無関係?)
-- 上記スクリーンショットの抜け部分のサイズは`32px`
-- [https://github.com/corretto/corretto-8/issues/127 Java2D rendering may break when using soft clipping effects · Issue #127 · corretto/corretto-8]、`8u222`で修正済み %%される予定%%
- [https://bugs.openjdk.org/browse/JDK-8225065 [JDK-8225065] Revert 8221166 (8u backport of 8048782) - Java Bug System]のリバートで`OpenJDK`でも`8u222`で修正済み %%される模様%%
-- `8u222`で修正される予定だった[https://github.com/corretto/corretto-8/pull/94 Backport JDK-8048782: OpenJDK: PiscesCache : xmax/ymax rounding up can cause RasterFormatException by sci-aws · Pull Request #94 · corretto/corretto-8]の修正が`corretto-8`では`8u212`に紛れ込んでいた?ということなのかも???
- `Corretto 11.0.3`では正常
openjdk version "11.0.3" 2019-04-16 LTS
OpenJDK Runtime Environment Corretto-11.0.3.7.1 (build 11.0.3+7-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.3.7.1 (build 11.0.3+7-LTS, mixed mode)
- `AdoptOpenJDK 1.8.0_212`では正常
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_212-b03)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.212-b03, mixed mode)
** 右Altキーが効かない [#g57772eb]
- [https://bugs.openjdk.org/browse/JDK-8194873 JDK-8194873 right ALT key hotkeys no longer work in Swing components - Java Bug System]
-- `Java 9`で右KBD{Alt}キーが効かなくなっている
--- `Java 8`は問題なし
--- `Java 11`で修正済み
** 高解像度でIMEの候補表示位置がずれる [#o7e09fe6]
- [https://bugs.openjdk.org/browse/JDK-8189687 JDK-8189687 Swing: Invalid position of candidate pop-up of InputMethod in Hi-DPI on Windows - Java Bug System]
-- `Java 11`で修正済み
** Application uses higher CPU in 8u161/8u162 [#md4c2938]
- [https://bugs.openjdk.org/browse/JDK-8195830 JDK-8195830 Application uses higher CPU in 8u161/8u162 - Java Bug System]
-- via: [https://stackoverflow.com/questions/48339199/java-8u161-8u162-makes-swing-app-use-cpu Java 8u161/8u162 makes Swing app use CPU - Stack Overflow]
-- 例えば`JTextField`などに日本語を入力しようとして`IME`を切り替えると`CPU`を浪費する
- `Java 10`での修正が`8u172`にもバックポートされた
-- [https://bugs.openjdk.org/browse/JDK-8183504 JDK-8183504 8u131 Win 10, issue with wrong position of Sogou IME popup - Java Bug System]
-- [https://bugs.openjdk.org/browse/JDK-8191889 JDK-8191889 8u131 Win 10, issue with wrong position of Sogou IME popup - Java Bug System]
** 親フレームのドラッグ中にJWindowでクラッシュ [#hed7be2e]
- [https://stackoverflow.com/questions/30072883/java-swing-jwindow-application-crash Java Swing JWindow application crash - Stack Overflow]
-- 親フレームのドラッグ中に?子`JWindow`が表示されると`JVM`が落ちる(`Windows 7 64bit JKD1.8.0_11`)。
--[https://bugs.openjdk.org/browse/JDK-8079595?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel JDK-8079595 Resizing dialog which is JWindow parent makes JVM crash - Java Bug System]
-- [https://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/b5125fa7ef4b jdk9 changeset 12899:b5125fa7ef4b 8079595: Resizing dialog which is JWindow parent makes JVM crash] 修正された模様
#code{{
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main2 {
private static Robot robot;
public static void main(String... args) throws Exception {
robot = new Robot();
robot.setAutoDelay(100);
EventQueue.invokeLater(new Runnable() {
@Override public void run() {
createAndShowGUI();
}
});
EventQueue.invokeAndWait(new Runnable() {
@Override public void run() {
Point pt = new Point(50, 10);
robot.mouseMove(pt.x, pt.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
pt.translate(50, 50);
robot.mouseMove(pt.x, pt.y);
//robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
});
}
public static void createAndShowGUI() {
final JFrame f = new JFrame();
f.add(new JLabel("Try JFrame draging 2sec"));
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.setSize(320, 240);
f.setVisible(true);
final JWindow w = new JWindow(f);
w.add(new JButton("button"));
w.pack();
Timer t = new Timer(2000, new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
w.setVisible(true);
}
});
t.setRepeats(false);
t.start();
}
}
}}
** TimSortでレイアウトをソート中に例外発生 [#decaf774]
- [https://stackoverflow.com/questions/16547365/swing-gui-flickering-white-error java - swing gui flickering white error - Stack Overflow]のサンプルを試していたら面白い挙動に遭遇。
-- `JDK1.8.0_40`で(以前のソートを使用するように)修正された
-- [https://bugs.openjdk.org/browse/JDK-8048887 JDK-8048887 SortingFocusTraversalPolicy throws IllegalArgumentException from the sort method]
- `JDK1.7.0_21`
-- IllegalArgumentException: Comparison method violates its general contract!
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Comparison method violates its general contract!
at java.util.TimSort.mergeLo(TimSort.java:747)
at java.util.TimSort.mergeAt(TimSort.java:483)
at java.util.TimSort.mergeCollapse(TimSort.java:410)
at java.util.TimSort.sort(TimSort.java:214)
at java.util.TimSort.sort(TimSort.java:173)
at java.util.Arrays.sort(Arrays.java:659)
at java.util.Collections.sort(Collections.java:217)
-- フレームのリサイズで上下左右に余白?
- `JDK1.6.0_41`
-- フレームのリサイズで右と下に余白?
#code{{
import java.awt.*;
import javax.swing.*;
public class Gui {
public JComponent makeUI() {
JPanel p = new JPanel(new GridLayout(22,12,10,10));
p.setBackground(Color.WHITE);
p.setBorder(BorderFactory.createLineBorder(Color.BLUE, 10));
for (int i = 0; i < 22; i++) {
for (int j = 0; j < 12; j++) {
JLabel label = new JLabel();
label.setBorder(BorderFactory.createLineBorder(Color.RED));
label.setBackground(Color.GRAY);
label.setOpaque(true);
//label.setPreferredSize(new Dimension(50, 50));
p.add(label);
}
}
return p;
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override public void run() {
createAndShowGUI();
}
});
}
public static void createAndShowGUI() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.getContentPane().add(new Gui().makeUI());
f.setSize(320, 240);
//f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
}}
* Reference [#reference]
** 未修正 [#w96f7a6e]
- [https://bugs.openjdk.org/browse/JDK-4280944 [JDK-4280944] Attributes on last newline character cause undesirable extra spacing. - Java Bug System]
- [https://bugs.openjdk.org/browse/JDK-4292511 [JDK-4292511] JTableHeader height determined by first column given HTML text - Java Bug System]
- [https://bugs.openjdk.org/browse/JDK-4765261 [JDK-4765261] JTextArea.append does not follow spec (it is not ThreadSafe) - Java Bug System]
- [https://bugs.openjdk.org/browse/JDK-5036549 [JDK-5036549] PopupMenu not adjusting its location correctly depending on taskbar's position. - Java Bug System]
- [https://bugs.openjdk.org/browse/JDK-6603771 [JDK-6603771] Nimbus L&F: Ctrl+F7 keybinding for JInternal Frame throws a NPE. - Java Bug System]
- [https://bugs.openjdk.org/browse/JDK-6612928 [JDK-6612928] Win32ShellFolder2 throws RejectedExecutionException on application exit - Java Bug System]
- [https://bugs.openjdk.org/browse/JDK-6700748 [JDK-6700748] Cursor flickering during D&D when using CellRendererPane with validation - Java Bug System]
- [https://bugs.openjdk.org/browse/JDK-6723524 [JDK-6723524] Invalid background of components displayed in JTable in Nimbus L&F - Java Bug System]
- [https://bugs.openjdk.org/browse/JDK-6723524 [JDK-6723524] Invalid background of components displayed in JTable in Nimbus L&F - Java Bug System]
- [https://bugs.openjdk.org/browse/JDK-6780505 [JDK-6780505] java.awt.Desktop.getDesktop().open() fails on shared files with white spaces - Java Bug System]
- [https://bugs.openjdk.org/browse/JDK-6826514 [JDK-6826514] SwingWorker: done() called before doInBackground() returns, when cancelled - Java Bug System]
** 修正済み [#ReleaseFixed]
- Release Fixed: 1.4.0 %%[https://bugs.openjdk.org/browse/JDK-4463424 [JDK-4463424] LineBreakMeasurer inconsistent with TextLayout - Java Bug System]%%
- Release Fixed: 1.6.0 %%[https://bugs.openjdk.org/browse/JDK-6413228 [JDK-6413228] Many links broken with "?is-external=true". - Java Bug System]%%
- Release Fixed: 1.7.0 %%[https://bugs.openjdk.org/browse/JDK-6910490 [JDK-6910490] MatteBorder JScrollpane interaction - Java Bug System]%%
- Release Fixed: 1.7.0 %%[https://bugs.openjdk.org/browse/JDK-4765383 [JDK-4765383] JTextArea.append(String) not thread safe - Java Bug System]%%
- Release Fixed: 1.7.0, 1.6.0_18 %%[https://bugs.openjdk.org/browse/JDK-4833524 [JDK-4833524] BasicTreeUI.isToggleSelectionEvent() does not properly handle popup triggers - Java Bug System]%%
- Release Fixed: 1.7.0, 1.6.0_18 %%[https://bugs.openjdk.org/browse/JDK-6840086 [JDK-6840086] JFileChooser lacks icons on top right when running on Windows 7 - Java Bug System]%%
- Release Fixed: 1.6.0_21 %%[https://bugs.openjdk.org/browse/JDK-6631956 [JDK-6631956] Nimbus: ClassCastException when running with MultiLookAndFeel - Java Bug System]%%
- 修正されているようだがクローズされていない %%[https://bugs.openjdk.org/browse/JDK-7140863 [JDK-7140863] Lots of Japanese OpenType fonts do not render correctly - Java Bug System]%%
* コメント [#comment]
* Comment [#comment]
#comment
#comment