Swing GUI に MigLayout ライブラリを使用しています。
次のように、2 つの JPanel をオーバーレイしたいと思います。
+----+-----------------------+
| 1 | 2 |
| | |
+----+ |
| |
| |
| |
| |
+----------------------------+
ビデオゲームのミニマップによく似ています。
これを達成するには2つの方法があるように私には思えます:
JLayeredPane
JPanel main = new JPanel();
main.setBounds(0, 0, WIDTH, HEIGHT);
// ... fill it with Swing components ...
JPanel minimap = new JPanel();
minimap.setBounds(10, 10, 100, 100);
/// ... fill it with Swing components ...
JLayeredPane layer = new JLayeredPane();
layer.add(main, new Integer(0));
layer.add(minimap, new Integer(1));
ただし、このアプローチは、 と を指定する必要があるため、脆弱WIDTH
ですHEIGHT
。ウィンドウのサイズが変更された場合、これらの値を再度計算する必要があるようです。
JLayeredPane & MigLayout
JPanel main = new JPanel();
// ... fill it with Swing components ...
JPanel minimap = new JPanel();
/// ... fill it with Swing components ...
JLayeredPane layer = new JLayeredPane();
layer.setLayoutManager(new MigLayout());
CC positioning;
positioning = // ??? something specified in percents and z-order?
layer.add(main, positioning, new Integer(0));
positioning = // ??? something specified in percents and z-order?
layer.add(minimap, positioning, new Integer(1));
WIDTH
(ピクセル解像度とは対照的にHEIGHT
、最初の例では)パーセント値を指定できるようにしながら、MigLayout を使用してオーバーレイを可能にする何かでポジショニング コードを埋めることは可能ですか?
編集:
部分的に機能するソリューションを次に示します。
positioning = new CC().width("100%").height("100%");
// ...
positioning = new CC().pos("10", "10");
ただし、ディスプレイが揺れて見えないことがあります。これは、不確定なレンダリング順序に関係していると思います (ただし、それは単なる直感です)。