Render a single cell in a table using Java

17 views (last 30 days)
Yuval Mika
Yuval Mika on 30 Jan 2019
I have a sample code creating a simple uitable object and trying to render one of its cells. The code is running with no exceptions but the cell's color does not change. Any ideas what might be the problem?
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
f = figure;
hTable = uitable(f,'Data',randi(100,10,3));
jScroll = findjobj(hTable);
jTable = jScroll.getViewport.getView;
row = 1;
col = 1;
renderer = jTable.getCellRenderer(row, col);
value = jTable.getValueAt(row, col);
comp = renderer.getTableCellRendererComponent(...
jTable, value, false, false, row,...
col);
comp.setBackground(Color(1,1,0));
column = jTable.getColumnModel().getColumn(col);
column.setCellRenderer(comp);

Answers (0)

Categories

Find more on Construct and Work with Object Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!