Table - potatoscript/JavaSwing GitHub Wiki

  1. Set the table properties
  DefaultTableModel model1 = new DefaultTableModel(rowData, columnNames);
  final JTable jTable1 = new JTable(model1);
  jTable1.setBackground(Color.orange);
  jTable1.setForeground(Color.blue);
  jTable1.setRowHeight(24);
  jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  
  JScrollPane scrollableTextArea = new JScrollPane(jTable1);

  scrollableTextArea.setHorizontalScrollBarPolicy(...);
  JTable table = new JTable(rowData, columnNames){
     public Component prepareRenderer(TableCellRenderer renderer, int row, int col){
        Component comp = super.prepareRenderer(renderer, row, col);
        Object value = getModel().getValueAt(row,col);
        ((JLabel)comp).setHorizontalAlignment(JLabel.CENTER);
        
        comp.setFreground(Color.BLACK);
        comp.setFont(new Font("HGPグックM",FONT.BOLD,18));
        Color lightBlue = new Color(173,216,230);
        Color lightCoral = new Color(240,128,128);

        if(value.equals("xxx")){
           comp.setBackground(Color.magenta);
        }else{
           comp.setBackground(lightCarol);
        }else{
           comp.setBackground(Color.white);
        }
        return comp;
     }
  };
  table.setRowHeight(25);
  table.setPreferredScrollableViewportSize(
        table.getPreferredSize());

  JScrollPane scrollableTextArea = new JScrollPane(table);
  scrollableTextArea.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  scrollableTextArea.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
  
  createLayout(quitButton, btn, coords, scrollableTextArea);

}//end of Jtable table