samona Posted February 29, 2012 Share Posted February 29, 2012 I need some help printing a jtable so that the table prints 50% of what the normal print size would be. Any ideas on how I can control the Jtable's print size? Quote Link to comment https://forums.phpfreaks.com/topic/257995-java-jtable/ Share on other sites More sharing options...
Maq Posted February 29, 2012 Share Posted February 29, 2012 You set it in the cellrenderer. There are a few ways to do this depending on how you're building your table. Show us your code. Quote Link to comment https://forums.phpfreaks.com/topic/257995-java-jtable/#findComment-1322439 Share on other sites More sharing options...
Maq Posted February 29, 2012 Share Posted February 29, 2012 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)); Quote Link to comment https://forums.phpfreaks.com/topic/257995-java-jtable/#findComment-1322450 Share on other sites More sharing options...
samona Posted February 29, 2012 Author Share Posted February 29, 2012 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) {} Quote Link to comment https://forums.phpfreaks.com/topic/257995-java-jtable/#findComment-1322451 Share on other sites More sharing options...
Maq Posted February 29, 2012 Share Posted February 29, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/257995-java-jtable/#findComment-1322455 Share on other sites More sharing options...
samona Posted February 29, 2012 Author Share Posted February 29, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257995-java-jtable/#findComment-1322456 Share on other sites More sharing options...
Maq Posted February 29, 2012 Share Posted February 29, 2012 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); Quote Link to comment https://forums.phpfreaks.com/topic/257995-java-jtable/#findComment-1322463 Share on other sites More sharing options...
samona Posted March 1, 2012 Author Share Posted March 1, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/257995-java-jtable/#findComment-1322767 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.