2010-06-27 25 views

risposta

0

Forse questo aiuta, non ho ancora testato, però

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); 
    } 
} 
} 

Questa non è la mia, tratto da here

+0

beh questo è per le celle non per le intestazioni. – Xorty

3

Questo è po 'complicata. Per prima cosa, devi lanciare intestazioni JTable su JLabels. E 'proprio come

((JLabel)table.getTableHeader() 

Poi ruotare JLabels. Ha già risposto here on StackOverflow