OSDN Git Service

カスタムJTable
authoryukihane <yukihane.feather@gmail.com>
Mon, 29 Aug 2011 07:21:55 +0000 (16:21 +0900)
committeryukihane <yukihane.feather@gmail.com>
Mon, 29 Aug 2011 07:48:57 +0000 (16:48 +0900)
frontend/src/yukihane/inqubus/gui/MainFrame.java
frontend/src/yukihane/inqubus/gui/MainTable.java [new file with mode: 0644]

index 76461fd..4fd93b2 100644 (file)
@@ -106,7 +106,7 @@ public class MainFrame extends JFrame {
 
         final JPanel pnlMain = new JPanel();
         final JScrollPane scrDisplay = new JScrollPane();
 
         final JPanel pnlMain = new JPanel();
         final JScrollPane scrDisplay = new JScrollPane();
-        tblDisplay = new JTable();
+        tblDisplay = new MainTable();
         final JPanel pnlButton = new JPanel();
         btnStart = new JButton();
         btnStop = new JButton();
         final JPanel pnlButton = new JPanel();
         btnStart = new JButton();
         btnStop = new JButton();
diff --git a/frontend/src/yukihane/inqubus/gui/MainTable.java b/frontend/src/yukihane/inqubus/gui/MainTable.java
new file mode 100644 (file)
index 0000000..f637e76
--- /dev/null
@@ -0,0 +1,53 @@
+package yukihane.inqubus.gui;
+
+import java.awt.Component;
+import javax.swing.JProgressBar;
+import javax.swing.JTable;
+import javax.swing.table.TableCellRenderer;
+import yukihane.inqubus.model.Progress;
+
+/**
+ *
+ * @author yuki
+ */
+public class MainTable extends JTable {
+
+    public MainTable() {
+        super();
+        setDefaultRenderer(Progress.class, new ProgressRenderer());
+    }
+
+    @Override
+    public TableCellRenderer getCellRenderer(int row, int column) {
+        return super.getCellRenderer(row, column);
+    }
+}
+
+class ProgressRenderer extends JProgressBar implements TableCellRenderer {
+
+    private static final long serialVersionUID = 1L;
+
+    public ProgressRenderer() {
+        super(0, 100);
+        setStringPainted(true);
+    }
+
+    @Override
+    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
+            int row, int column) {
+        if (value == null) {
+            return this;
+        }
+
+        final Progress p = (Progress) value;
+        int percent = (int) p.getPercent();
+        if (percent < 0 || percent > 100) {
+            percent = 100;
+        }
+        setValue(percent);
+        setString(p.getText());
+        System.out.println(percent + "," + p.getText());
+
+        return this;
+    }
+}