私は戦艦ゲームを作成しており、ペイン内のボタンを制御してドラッグ ドロップし、デフォルトのリスト モデルでインデックスを追跡できるようにする方法を見つけようとしています。文字列または ImageIcons を追加すると、正常に動作します。しかし、ボタンを使用すると、何か違うものになります。
これが私のコードです:
public class ListModelExample extends JPanel {
  JList list;
  DefaultListModel model;
  int counter = 15;
  public ListModelExample() {
    setLayout(new BorderLayout());
    model = new DefaultListModel();
    list = new JList(model);
    JScrollPane pane = new JScrollPane(list);
    JButton addButton = new JButton("Add Element");
    JButton removeButton = new JButton("Remove Element");
    final JButton button = new JButton("button");
    for (int i = 0; i < 5; i++)
      model.addElement(button);
    addButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        model.addElement(button);
        counter++;    
      }
    });
    removeButton.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        if (model.getSize() > 0)
          model.removeElementAt(0);
      }
    });
    add(pane, BorderLayout.NORTH);
    add(addButton, BorderLayout.WEST);
    add(removeButton, BorderLayout.EAST);
  }
  public static void main(String s[]) {
    JFrame frame = new JFrame("List Model Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new ListModelExample());
    frame.setSize(260, 200);
    frame.setVisible(true);
  }
}
ボタンを追加すると、次の結果が得られます。

だから私の質問は次のとおりです。デフォルトのリストモデルでテキストとしてではなく、ボタンを通常どおりに表示するにはどうすればよいですか?