2
I wanted to know how to make a Tablecellrenderer for strings.
on this topic here: How to use a selection setBackground in custom Renderer?
I saw that the guy had to "values". I wanted to know if to do for names and etc?
For example:
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class Tabela extends JFrame {
public static void main(String args[]) {
new Tabela();
}
public Tabela() {
String[][] dados = new String[][]{{"Brasil", "São Paulo"},
{"Estados Unidos", "New York"}
};
String[] colunas = new String[]{"Pais", "Estado"};
JTable tabela = new JTable(dados, colunas);
JScrollPane jsp = new JScrollPane(tabela);
jsp.setPreferredSize(new Dimension(200, 300));
getContentPane().add("Center", jsp);
setSize(500, 300);
setVisible(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
I have a table (here only a very simple example), and I wish I could have a render, so where I have tables later, I can format them. I wanted the names there to be centralized (content of the lines)
It’s still unclear what you want. Centering columns with string doesn’t even need to create a Renderer. That’s all you want: to centralize column information?
– user28595
Center the contents of rows. Any row q is inserted is centered.
– user59450