私のJavaアプリケーションには2つのjbuttonがあります。私も2つのjpanelsを持っています。これらの 2 つの jpanels は異なる内容を持っています。つまり、互いに関連していません。ユーザーがボタンをクリックするたびに、対応するjpanelを同じ場所に表示する必要があります(jpanelの幅と高さは異なります)。
netbeans でそれを実行しようとすると、1 つの jpanel が別の jpanel 内に含まれています
private void button1ActionPerformed(java.awt.event.ActionEvent evt)
{
// TODO add your handling code here:
button1panel.setVisible(true);
//all other panel's visibility is false
}
ボタン2のように、私はこのようなアクションリスナーを持っています
private void button2ActionPerformed(java.awt.event.ActionEvent evt)
{
// TODO add your handling code here:
//all other panel's visibility is false
button2panel.setVisible(true);
}
これらの 2 つのパネルを上下に配置して (button1panel の上に button2panel)、同じ場所でアクセスできるようにしました。
しかし、button2panel.setVisible(true) を呼び出すと、button2panel の幅と高さが小さいため、実際には有効になりません。
私のデモンストレーションでは、button2panel が button1panel の内側にあり、button1panel の可視性が false であるため、それが起こっていると言っています。
私にできることは、button2panelをbutton1panelの外に出すことですが、これを行うと、パネルの場所が異なります
それを修正する方法??
またはこれに対するより良い解決策??