アプレットにテーブルを表示するコードがあり、2 つの列で構成されています。
- 画像アイコン
- 説明
これが私のコードです:
import javax.swing.table.*;
public class TableIcon extends JFrame
{
public TableIcon()
{
ImageIcon aboutIcon = new ImageIcon("about16.gif");
ImageIcon addIcon = new ImageIcon("add16.gif");
ImageIcon copyIcon = new ImageIcon("copy16.gif");
String[] columnNames = {"Picture", "Description"};
Object[][] data =
{
{aboutIcon, "About"},
{addIcon, "Add"},
{copyIcon, "Copy"},
};
DefaultTableModel model = new DefaultTableModel(data, columnNames);
JTable table = new JTable( model )
{
// Returning the Class of each column will allow different
// renderers to be used based on Class
public Class getColumnClass(int column)
{
return getValueAt(0, column).getClass();
}
};
table.setPreferredScrollableViewportSize(table.getPreferredSize());
JScrollPane scrollPane = new JScrollPane( table );
getContentPane().add( scrollPane );
}
public static void main(String[] args)
{
TableIcon frame = new TableIcon();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack();
frame.setVisible(true);
}
}
今私が知りたいのは、テーブルから特定の画像を選択し、テキスト領域またはテキストフィールドに表示するように、選択リスナーまたはマウスリスナーイベントをテーブルに実装する方法です(テーブルには画像ファイルのパスが含まれています)?
テーブルにテキスト フィールドとフレームにテーブルを追加できますか? 必要な場合はお気軽にご質問ください。