wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Change values in the header of a table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Change values in the header of a table" Watch "Change values in the header of a table" New topic
Author

Change values in the header of a table

Laurent Quenon
Greenhorn

Joined: Dec 09, 2003
Posts: 11
Hello all,
I created a table with a jtable component, this table is inside a non scrollable panel. (Fixed size table)
So, I found on the net that to display the header, I have to use the Jtableheader class and display the header myself. It's what I did and it works. But now I just would like to change the values that are in the header by default (A,B,C) and put names like (Licence number, name ,...).
I know that it should be stupid but I can't figure out how to proceed to do this basic stuff.
Here is the complete code of my form, the part I am talking about is between // HERE IS THE PIECE OF CODE and //TILL HERE.
package presentation;
import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.table.JTableHeader;
public class Teamedit extends javax.swing.JPanel {
JTable tblOfficielsLeft;
JTextField txtTeamLeft;
JLabel labTeamedtTitle;
JComboBox combTeamleft;
JTable tblLiberoLeft;
JTable tblPlayersLeft;
JPanel panTeamLeft;
JTable tblLiberoRight;
JTable tblPlayersRight;
JTable tblOfficielsRight;
JPanel panTeamRight;
JPanel panPlayersLeft;
JComboBox combTeamRight;
JTextField txtTeamRight;
JTableHeader thPlayersleft;
public Teamedit() {
initGUI();
}
/**
* Initializes the GUI.
* Auto-generated code - any changes you make will disappear.
*/
public void initGUI() {
try {
preInitGUI();
txtTeamRight = new JTextField();
combTeamRight = new JComboBox();
panTeamRight = new JPanel();
tblOfficielsRight = new JTable(4,2);
tblPlayersRight = new JTable(12,3);
tblLiberoRight = new JTable(1,3);
panTeamLeft = new JPanel();
panPlayersLeft = new JPanel();
tblPlayersLeft = new JTable(12,3);
tblLiberoLeft = new JTable(1,3);
tblOfficielsLeft = new JTable(4,2);
combTeamleft = new JComboBox();
labTeamedtTitle = new JLabel();
txtTeamLeft = new JTextField();
thPlayersleft = tblPlayersLeft.getTableHeader();
this.setLayout(null);
this.setFont(new java.awt.Font("", 0, 8));
this.setPreferredSize(new java.awt.Dimension(476, 402));
txtTeamRight.setVisible(true);
txtTeamRight.setPreferredSize(new java.awt.Dimension(129, 30));
txtTeamRight.setBounds(new java.awt.Rectangle(291, 5, 129, 30));
this.add(txtTeamRight);
combTeamRight.setVisible(true);
combTeamRight.setPreferredSize(new java.awt.Dimension(38, 30));
combTeamRight.setBounds(new java.awt.Rectangle(432, 5, 38, 30));
this.add(combTeamRight);
panTeamRight.setLayout(null);
panTeamRight.setVisible(true);
panTeamRight.setPreferredSize(new java.awt.Dimension(232, 356));
panTeamRight.setBorder(
new LineBorder(new java.awt.Color(0, 0, 0), 1, false));
panTeamRight.setBounds(new java.awt.Rectangle(240, 42, 232, 356));
this.add(panTeamRight);
tblOfficielsRight.setLayout(null);
tblOfficielsRight.setVisible(true);
tblOfficielsRight.setPreferredSize(new java.awt.Dimension(215, 48));
tblOfficielsRight.setBounds(
new java.awt.Rectangle(6, 299, 215, 48));
panTeamRight.add(tblOfficielsRight);
tblPlayersRight.setLayout(null);
tblPlayersRight.setVisible(true);
tblPlayersRight.setPreferredSize(new java.awt.Dimension(215, 192));
tblPlayersRight.setBounds(new java.awt.Rectangle(6, 16, 215, 192));
panTeamRight.add(tblPlayersRight);
tblLiberoRight.setLayout(null);
tblLiberoRight.setVisible(true);
tblLiberoRight.setPreferredSize(new java.awt.Dimension(215, 15));
tblLiberoRight.setBounds(new java.awt.Rectangle(6, 266, 215, 15));
panTeamRight.add(tblLiberoRight);
panTeamLeft.setLayout(null);
panTeamLeft.setVisible(true);
panTeamLeft.setPreferredSize(new java.awt.Dimension(229, 356));
panTeamLeft.setBorder(
new LineBorder(new java.awt.Color(0, 0, 0), 1, false));
panTeamLeft.setBounds(new java.awt.Rectangle(6, 42, 229, 356));
this.add(panTeamLeft);
tblPlayersLeft.setLayout(null);
tblPlayersLeft.setEditingColumn(3);
tblPlayersLeft.setEditingRow(12);
tblPlayersLeft.setVisible(true);
tblPlayersLeft.setPreferredSize(new java.awt.Dimension(215, 192));
tblPlayersLeft.setBounds(new java.awt.Rectangle(3, 3, 215, 192));
//tblPlayersLeft.setTableHeader();
// HERE IS THE PIECE OF CODE
panPlayersLeft.setLayout(new BorderLayout());
panPlayersLeft.setVisible(true);
panPlayersLeft.setPreferredSize(new java.awt.Dimension(220, 208));
panPlayersLeft.setBorder(
new LineBorder(new java.awt.Color(0, 0, 0), 0, false));
panPlayersLeft.setBounds(new java.awt.Rectangle(6, 16, 220, 208));
panTeamLeft.add(panPlayersLeft);
panPlayersLeft.add(thPlayersleft,BorderLayout.NORTH);
panPlayersLeft.add(tblPlayersLeft, BorderLayout.CENTER);
//TILL HERE
tblLiberoLeft.setLayout(null);
tblLiberoLeft.setVisible(true);
tblLiberoLeft.setPreferredSize(new java.awt.Dimension(215, 15));
tblLiberoLeft.setBounds(new java.awt.Rectangle(6, 266, 215, 15));
panTeamLeft.add(tblLiberoLeft);
tblOfficielsLeft.setLayout(null);
tblOfficielsLeft.setVisible(true);
tblOfficielsLeft.setPreferredSize(new java.awt.Dimension(215, 48));
tblOfficielsLeft.setBounds(
new java.awt.Rectangle(6, 299, 215, 48));
panTeamLeft.add(tblOfficielsLeft);
combTeamleft.setVisible(true);
combTeamleft.setPreferredSize(new java.awt.Dimension(38, 30));
combTeamleft.setBounds(new java.awt.Rectangle(5, 5, 38, 30));
this.add(combTeamleft);
labTeamedtTitle.setLayout(null);
labTeamedtTitle.setText("Noms des Equipes");
labTeamedtTitle.setHorizontalAlignment(0);
labTeamedtTitle.setHorizontalTextPosition(0);
labTeamedtTitle.setVisible(true);
labTeamedtTitle.setFont(new java.awt.Font("", 0, 9));
labTeamedtTitle.setPreferredSize(new java.awt.Dimension(88, 30));
labTeamedtTitle.setBorder(
new BevelBorder(1, null, null, null, null));
labTeamedtTitle.setBounds(new java.awt.Rectangle(195, 4, 88, 30));
this.add(labTeamedtTitle);
txtTeamLeft.setVisible(true);
txtTeamLeft.setPreferredSize(new java.awt.Dimension(129, 30));
txtTeamLeft.setBounds(new java.awt.Rectangle(55, 5, 129, 30));
this.add(txtTeamLeft);
postInitGUI();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Add your pre-init code in here
*/
public void preInitGUI() {
}
/**
* Add your post-init code in here
*/
public void postInitGUI() {
}
/** Auto-generated main method */
public static void main(String[] args) {
showGUI();
}
/**
* Auto-generated code - any changes you make will disappear!!!
* This static method creates a new instance of this class and shows
* it inside a new JFrame, (unless it is already a JFrame).
*/
public static void showGUI() {
try {
JFrame frame = new JFrame();
Teamedit inst = new Teamedit();
frame.setContentPane(inst);
frame.pack();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Thanks a lot for your help.
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8839
    
    7

Originally posted by Laurent Quenon:

So, I found on the net that to display the header, I have to use the Jtableheader class and display the header myself.

JTable DOES create it's own JTableHeader instance, it just doesn't display it in your situation. You can get to the instance by invoking getTableHeader(). I mention this because the easiest way to customize the header is to use the JTable constructor. You can pass it either an Object array (with an 2d Object array of data) or Vector (with a Vector of Vectors of Object data) of column names.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Change values in the header of a table
 
Similar Threads
JTable
Color in JTable
Updating values in a jTable
JTable
JTable