2
How do I change the size of the vertical grid lines of a Jtable?
Ex:
jTable.setRowHeight(30);
This method above changes the line width.
Have some other similar to this which changes the vertical grid width of the columns?
Below an image to illustrate what I want to change the width.
Edit:
I’m doing so but still it didn’t work what I’m doing wrong?
public class GuiPrincipal extends JFrame {
//variaveis para uso da JTable
private JTable table;
private final String colunas[] = {"Nome:", "Idade:", "Sexo:"};
private final String dados[][] = {
{"Jack", "19", "Masculino"},
{"Eddie", "56", "Masculino"},
{"Gina", "34", "Feminino"},
{"Klaus", "18", "Masculino"},
{"Erika", "20", "Feminino"},
{"Roberto", "29", "Masculino"},
{"Maria", "30", "Feminino"}};
/*Construtor da classe ,
antes de executar o metodo main(),
irá construir o JFrame e a JTable*/
public GuiPrincipal() {
setLayout(new FlowLayout());//tipo de layout
setSize(new Dimension(700, 300));//tamanho do Formulario
setLocationRelativeTo(null);//centralizado
setTitle("Exemplo JTable");//titulo
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//setando a ação padrão de fechamento do Formulário,
// neste caso irá fechar o programa
//instanciando a JTable
table = new JTable(dados, colunas);
table.setPreferredScrollableViewportSize(new Dimension(700, 300));//barra de rolagem
table.setFillsViewportHeight(true);
//adicionando a tabela em uma barra de rolagem, ficará envolta , pela mesma
JScrollPane scrollPane = new JScrollPane(table);
table.setDefaultRenderer(String.class, new Renderer());
add(scrollPane);
}
//este é o método onde é executado nosso programa
public static void main(String[] args) {
new GuiPrincipal().setVisible(true);
}
}
And below the class of Nderer.
public class Renderer extends DefaultTableCellRenderer {
javax.swing.border.Border padding = BorderFactory.createEmptyBorder(50, 50, 50, 50);
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
row, column);
setBorder(BorderFactory.createCompoundBorder(getBorder(), padding));
return this;
}
}
Already tried to go in the column and search for setColumnWidth?
– Gustavo Fragoso
I don’t want to mess with the size of the column.
– Vinicius Silva
I can not see the image, what you intend to do? I could not understand without seeing it.
– user28595
There is a separator between the columns of the J table that looks like this | column1| column2 | . What I want is to increase the size of this space so it gets about 5 times wider.Ps: It’s not the size of the column.
– Vinicius Silva
The solution below did not serve? Despite creating an edge to do this, it kind of "increases" this separator.
– user28595
At least the way I implemented in the above code had no result.
– Vinicius Silva
In fact, I tested and she really doesn’t do what you want. See if I elaborate something here.
– user28595