2010-06-27 81 views

回答

0

也許這會有所幫助,我沒有測試它雖然

class RotatedTableCellRenderer extends JLabel implements TableCellRenderer 
     { 
      protected int m_degreesRotation = -90; 

    public RotatedTableCellRenderer(int degrees) 
    { 
     m_degreesRotation = degrees; 
} 

    public Component getTableCellRendererComponent(JTable table, Object value, 
boolean isSelected, boolean hasFocus, int row, int column) 
    { 
    try 
    { 
      this.setText(value.toString()); 
    } 
    catch(NullPointerException ne) 
    { 
    this.setText("Nullvalue"); 
    } 
     return this; 
    } 

    public void paint(Graphics g) 
    { 
    Graphics2D g2 = (Graphics2D)g; 
    g2.setClip(0,0,500,500); 
    g2.setColor(new Color(60,179,113)); 
    g2.setFont(new Font("Arial",Font.BOLD,12)); 
    AffineTransform at = new AffineTransform(); 
    at.setToTranslation(this.getWidth(), this.getHeight()); 
    g2.transform(at); 
    double radianAngle = (((double)m_degreesRotation)/((double)180)) * Math.PI; 
    at.setToRotation(radianAngle); 
    g2.transform(at); 
    g2.drawString(this.getText(), 0.0f, 0.0f); 
    } 
} 
} 

這不是我自己的,從here

+0

那麼這是細胞不是頭。 – Xorty 2010-06-27 21:17:55

3

這是有點棘手拍攝。首先,您需要將JTable標頭強制轉換爲JLabels。這就像

((JLabel)table.getTableHeader() 

然後旋轉的JLabel。它已經回答了here on StackOverflow