Popular Posts
android.intent.action.SCREEN_ON & android.intent.action.SCREEN_OFF First, I've tried create a receiver to receive screen on/off and register receiver on AndroidManifest.xml like below, but unfortunately ... runas RUNAS 使用方法: RUNAS [ [/noprofile | /profile] [/env] [/netonly] ] /user: program RUNAS [ [/noprofile | /profile] [/env] [/netonly] ... Diff Time DateTime from = new DateTime(2011, 1, 7); DateTime to = DateTime.Now; TimeSpan ts = to - from; Console.WriteLine("start time : {0:yyyy...
Stats
JTable : multi line cell
table.getColumnModel().getColumn(i).setCellRenderer(new DefaultTableCellRenderer() {
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        String v = (String) value;
        String[] vs = v.split("\n");

        JPanel p = new JPanel(new GridLayout(vs.length, 1)) {
            @Override
            public void setForeground(Color fg) {
                for (int i = 0; i < getComponentCount(); i++) {
                    getComponent(i).setForeground(fg);
                }
                super.setForeground(fg);
            }

            @Override
            public void setBackground(Color bg) {
                for (int i = 0; i < getComponentCount(); i++) {
                    getComponent(i).setBackground(bg);
                }
                super.setBackground(bg);
            }
        };

        // 內容
        for (String s : vs) {
            JLabel l = new JLabel(s, JLabel.LEFT);
            l.setOpaque(true);
            p.add(l);
        }
        // 列高
        table.setRowHeight(row, table.getRowHeight() * vs.length);

        // 顏色設定
        p.setOpaque(true);
        p.setBackground(Color.white);

        // 變更背景及字體 顏色同, 同時變更內部元件的顏色
        if (isSelected) {
            p.setBackground(UIManager.getColor("Table.selectionBackground"));
            p.setForeground(UIManager.getColor("Table.selectionForeground"));
        }

        if (hasFocus) {
            p.setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));

            if (table.isCellEditable(row, column)) {
                p.setForeground(UIManager.getColor("Table.focusCellForeground"));
                p.setBackground(UIManager.getColor("Table.focusCellBackground"));
            }
        } else {
            p.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
        }

        return p;
    }
});