1

いくつかのことを自動化するために JButton 関数を拡張しているので、この関数のみを追加しました。

public void addButton(Container container, int left, int top, int width, int height)
{

    this.setBounds(left, top, width, height);
    this.setSize(width, height);
    container.add(this);
    this.repaint();
}

そして、私は自分のパネルでこのコードを実行しています:

buttonLeft = new extendedButton("Left");
    buttonMiddle = new extendedButton("Middle");
    buttonRight = new extendedButton("Right");

    Insets inset = this.getInsets();

    setLayout(null);

    Container c = getContentPane();

    buttonLeft.addButton(c, inset.left, inset.top, 150, 50);
    buttonMiddle.addButton(c, inset.left + buttonLeft.WIDTH, inset.top, 150, 50);
    buttonRight.addButton(c, inset.left + buttonLeft.WIDTH + buttonRight.WIDTH, inset.top, 150, 50);

ただし、ボタンが隣り合って表示されることを期待していますが、ボタンが上下に 1 ピクセル右に表示されているようです。ただし、.WIDTH パラメータを 150 に置き換えると、期待どおりに機能します。.WIDTH が設定した値を与えることを拒否する理由の手がかりはありますか? 私はレイアウトを使用していません。パラメーターとして null を指定しました。

4

0 に答える 0