Jump to content

java jtable


samona

Recommended Posts

If you want to change the font for every cell you can simply set the font directly to your table:

            final JTable table = new JTable(data, columnNames);
            table.setFont(new Font("Serif", Font.BOLD, 20));

Link to comment
Share on other sites

thank you for the response.  below is my cell renderer.  I can only make the size of the data but not the actual table which what I want.

 

public class MyTableCellRenderer extends javax.swing.JLabel implements
        javax.swing.table.TableCellRenderer {
    
    
  
  
    
    public java.awt.Component getTableCellRendererComponent(
            javax.swing.JTable table, java.lang.Object value,
            boolean isSelected, boolean hasFocus, int rowIndex, int colIndex) {
        
        setText(value.toString());
        
        if (value.equals(null)) {
            
            return this;
        }
            javax.swing.JLabel label = new javax.swing.JLabel(value.toString());
            //label.setFont(new java.awt.Font("Helvetica Bold", java.awt.Font.PLAIN,7));
            label.setVerticalAlignment(javax.swing.SwingConstants.CENTER);
            label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
           // System.out.println("IN RENDER");
     
        return label;
        
        
    }
    
    public void validate() {}
    public void revalidate() {}
    protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {}
    public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {}
    

Link to comment
Share on other sites

Instead of statically calling these packages just import them at the top.

 

I can only make the size of the data but not the actual table which what I want.

That's a bit ambiguous, what part of the table do you want to increase the size to?  Padding, height, width, overall table size, what?

Have you looked at the documentation? - http://docs.oracle.com/javase/1.5.0/docs/api/javax/swing/JTable.html

 

Link to comment
Share on other sites

I want to change the actual table width and height to be smaller for printing purposes.  I want the table as a whole to be smaller.  Right now for printing I have  FIT_WIDTH which span across the whole page, but I want the table width to span only across half the page. 

 

I looked at the link before, but nothing jumps at me as to adjusting overall table size for printing.

Link to comment
Share on other sites

I want to change the actual table width and height to be smaller for printing purposes.  I want the table as a whole to be smaller.  Right now for printing I have  FIT_WIDTH which span across the whole page, but I want the table width to span only across half the page. 

 

I looked at the link before, but nothing jumps at me as to adjusting overall table size for printing.

I guess you could grab the screen size and just divide by 2 when you set the table size.  Try:

        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        table.setSize(screenSize.width / 2, screenSize.height / 2);

Link to comment
Share on other sites

That made no difference.  What I ended up doing is setting the column size.  I can't make out the table's data on the screen now, but at least it prints the way i want it.  However, it would be nice if I could adjust the print size without affecting the window on the screen.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.