{"id":499,"date":"2004-03-10T13:49:16","date_gmt":"2004-03-10T04:49:16","guid":{"rendered":"\/?p=499"},"modified":"2004-03-10T13:49:16","modified_gmt":"2004-03-10T04:49:16","slug":"image-list","status":"publish","type":"post","link":"https:\/\/www.hiro345.net\/blogs\/hiro345\/archives\/499.html","title":{"rendered":"Image List"},"content":{"rendered":"<p>\njavax.swing.JList\u3092\u3064\u304b\u3046\u3068\u3001\u753b\u50cf\u4ed8\u304d\u30ea\u30b9\u30c8\u304c\u7c21\u5358\u306b\u4f5c\u6210\u3067\u304d\u308b\u3002\u3053\u308c\u306fJava2 SDK \u306b\u3064\u3044\u3066\u3044\u308b jfc\/SwingSet2 \u306e\u30c7\u30e2\u306b\u3082\u542b\u307e\u308c\u3066\u3044\u308b\u306e\u3067\u77e5\u3063\u3066\u3044\u308b\u4eba\u3082\u591a\u3044\u3060\u308d\u3046\u3002\u30ea\u30b9\u30c8\u306e\u9805\u76ee\u306f\u672c\u6765\u306fjavax.swing.DefaultListModel\u3092\u4f7f\u3063\u3066\u4f5c\u6210\u3059\u308b\u3079\u304d\u3060\u304c\u3001\u4eca\u56de\u306f\u53c2\u7167\u3059\u308b\u3060\u3051\u306a\u306e\u3067\u304a\u624b\u8efd\u306a\u914d\u5217\u3092\u4f7f\u3063\u3066\u3044\u308b\u3002\n<\/p>\n<p>\n\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u30dd\u30a4\u30f3\u30c8\u306f\u3001\u63cf\u753b\u3092\u53d7\u3051\u6301\u3064Component\u3092\u8fd4\u5374\u3059\u308bgetListCellRendererComponent\u30e1\u30bd\u30c3\u30c9\u3092\u6301\u3064\u30af\u30e9\u30b9\u3092\u7528\u610f\u3059\u308b\u3068\u3044\u3046\u70b9\u3060\u3002\n<\/p>\n<p><!--more--><\/p>\n<div class=\"code\">package org.sssg.four.java;<\/p>\n<p>import java.awt.BorderLayout;<br \/>\nimport java.awt.Color;<br \/>\nimport java.awt.Component;<br \/>\nimport javax.swing.ImageIcon;<br \/>\nimport javax.swing.JFrame;<br \/>\nimport javax.swing.JLabel;<br \/>\nimport javax.swing.JList;<br \/>\nimport javax.swing.ListCellRenderer;<br \/>\nimport javax.swing.event.ListSelectionEvent;<br \/>\nimport javax.swing.event.ListSelectionListener;<\/p>\n<p>public class ImageList extends JFrame implements ListSelectionListener {<br \/>\n\tprivate JList jlist;<br \/>\n\tpublic ImageList() {<br \/>\n\t\tgetContentPane().setLayout(new BorderLayout());<br \/>\n\t\tjlist = new JList(new String[]{ &#8220;Java&#8221;, &#8220;C++&#8221;, &#8220;Lisp&#8221;, });<br \/>\n\t\tjlist.setCellRenderer(new ImageCellRenderer());<br \/>\n\t\tjlist.addListSelectionListener(this);<br \/>\n\t\tgetContentPane().add(jlist, BorderLayout.CENTER);<br \/>\n\t\tsetSize(150, 140);<br \/>\n\t}<br \/>\n\tpublic void valueChanged(ListSelectionEvent e) {<br \/>\n\t\tif (e.getValueIsAdjusting()) {<br \/>\n\t\t\treturn;<br \/>\n\t\t}<br \/>\n\t\tObject[] selected = jlist.getSelectedValues();<br \/>\n\t\tfor (int i = 0; i < selected.length; i++) {\n\t\t\tSystem.out.println(selected[i]);\n\t\t}\n\t}\n\tclass ImageCellRenderer extends JLabel implements ListCellRenderer {\n\t\tpublic Component getListCellRendererComponent(\n\t\t\tJList list,\n\t\t\tObject value,\n\t\t\tint index,\n\t\t\tboolean isSelected,\n\t\t\tboolean cellHasFocus) {\n\t\t\tsetText(value.toString());\n\t\t\tif (isSelected) {\n\t\t\t\tsetForeground(Color.BLUE);\n\t\t\t} else { \n\t\t\t\tsetForeground(Color.BLACK);\n\t\t\t}\n\t\t\tsetIcon(new ImageIcon(\"about.png\"));\n\t\t\treturn this;\n\t\t}\n\t}\n\tpublic static void main(String[] args) {\n\t\tImageList f = new ImageList();\n\t\tf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n\t\tf.setVisible(true);\n\t}\n}<\/div>\n","protected":false},"excerpt":{"rendered":"<p>javax.swing.JList\u3092\u3064\u304b\u3046\u3068\u3001\u753b\u50cf\u4ed8\u304d\u30ea\u30b9\u30c8\u304c\u7c21\u5358\u306b\u4f5c\u6210\u3067\u304d\u308b\u3002\u3053\u308c\u306fJava2 SDK \u306b\u3064\u3044\u3066\u3044\u308b jfc\/SwingSet2 \u306e\u30c7\u30e2\u306b\u3082\u542b\u307e\u308c\u3066\u3044\u308b\u306e\u3067\u77e5\u3063\u3066\u3044\u308b\u4eba\u3082\u591a\u3044\u3060\u308d\u3046\u3002\u30ea\u30b9\u30c8\u306e\u9805\u76ee\u306f\u672c\u6765\u306f &hellip; <a href=\"https:\/\/www.hiro345.net\/blogs\/hiro345\/archives\/499.html\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-499","post","type-post","status-publish","format-standard","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/comments?post=499"}],"version-history":[{"count":0,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/posts\/499\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/media?parent=499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/categories?post=499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiro345.net\/blogs\/hiro345\/wp-json\/wp\/v2\/tags?post=499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}