JTable printing . . .

I have customized the column widths of a JTable to display properly on screen. But this size of the JTable doesn't looks good on the print when i set the JTable.PrintMode.FIT_WIDTH option, which produces small table on paper. But when the column widths are reduced on screen it looks very good on paper, and losses its look on screen.So, i want to make the table to fit width both on the screen and paper also. How to achieve this
Thank you.

Posted On: Monday 22nd of October 2012 12:36:06 AM Total Views:  257
View Complete with Replies

Related Messages:

create a jtable which can combine and split and the image change also   (149 Views)
hi newbie here and would like to know how to create a jtable with default images and with specific column and rows that if you combine the cells the image enlarge and when split the image decreases.
jtable, defaulttable model   (145 Views)
hello how can i remove column in JTable i have already made a button that when triggered it will add column through DefaultTableModel tbl = new DefaultTableModer(): tbl.addColumn(columnList.get(x)) now what im trying to do is make a column vanish T T and im surprised i did not see a removeColumn method xD is there anyway i can remove columns through runtime and if JTable.remove(component) is the answer how how can i use it xD
Generating pdf from jtable   (138 Views)
I am developing a tool in java to generate pdf from jtable. I tried to use itext but I am getting black pdf. Below is the code that I used. import java.awt.BorderLayout; import java.awt.Graphics2D; import java.awt.Shape; import; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTable; //import com.itextpdf.awt.PdfGraphics2D; import com.itextpdf.text.Document; import com.itextpdf.text.PageSize; import com.itextpdf.text.pdf.PdfContentByte; //import com.itextpdf.text.pdf.PdfTemplate; import com.itextpdf.text.pdf.PdfWriter; public class Pdf extends JFrame { /** * */ private static final long serialVersionUID = 1L; private JTable table; public Pdf() { getContentPane().setLayout(new BorderLayout()); createTable(); } private void createTable() { Object[][] data = {{ "a", "b", "e", new Integer(5), new Boolean(false) } }; String[] columnNames = { "A", "B", "C", "D", "E" }; table = new JTable(data, columnNames); JPanel tPanel = new JPanel(new BorderLayout()); tPanel.add(table.getTableHeader(), BorderLayout.NORTH); tPanel.add(table, BorderLayout.CENTER); getContentPane().add(tPanel, BorderLayout.CENTER); } private void print() { Document document = new Document(PageSize.A4.rotate()); try { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("jTable.pdf"));; PdfContentByte cb = writer.getDirectContent(); cb.saveState(); Graphics2D g2 = cb.createGraphicsShapes(500, 500); Shape oldClip = g2.getClip(); g2.clipRect(0, 0, 500, 500); table.print(g2); g2.setClip(oldClip); g2.dispose(); cb.restoreState(); } catch (Exception e) { System.err.println(e.getMessage()); } document.close(); } public static void main(String[] args) { Pdf frame = new Pdf(); frame.pack(); frame.setVisible(true); frame.print(); } }
Create and dynamically change buttons in jtable column   (193 Views)
I am having a lot of problems fully grasping tablecellrenderer and tablecelleditor. I have researched a lot, looked in a lot of forums, but still can't solve my problem. Without posting an sscce (because my code is probably very incorrect), how would I do the following: Create a jtable with a column that has ButtonX in it. Then when another column in a specific row gets a certain value, ButtonX will change to ButtonY, but other rows will remain what they are already. In the following example, all rows started with ButtonX, but when Progress changed from Uploading to Complete, ButtonX became ButtonY. Row Name Progress Abort/Complete 0 File 1 Complete ButtonY 1 File 2 Complete ButtonY 2 File 3 Uploading ButtonX The buttons need to update accordingly if a row is deleted. For example if row 0 is deleted, it should look like: Row Name Progress Abort/Complete 0 File 2 Complete ButtonY 1 File 3 Uploading ButtonX
Request focus for the first cell of a jtable.   (202 Views)
I'm having a JTable which is having text field in each of its cell. I would like to set the cursor in the first cell of each row in the Jtable. I'm trying to find some solution but not able to succeed. Please provide me some working example. Quick solution will be appreciated. TableColumn column0 = jTable2.getColumnModel().getColumn(0); JTextField textField = new JTextField(); textField.requestFocus(); DefaultCellEditor cellEditorFristColumn = new DefaultCellEditor(textField); column0.setCellEditor(cellEditorFristColumn); DefaultTableCellRenderer defaultRenderer = new DefaultTableCellRenderer(); defaultRenderer.requestFocus(); jTable2.getColumnModel().getColumn(0).setCellRenderer(defaultRenderer);
Inserting single column values of database table into multiple columns of jtable and do comparison   (178 Views)
all, I am struck ed in inserting single column values of database table into multiple columns of jtable and doing comparison for selecting greater values in each row. Is their any query that splits column values. here i am attaching the code please give me the solution. public void disp( final String n, final String p, final String f, final String t){ try{ rs1=st.executeQuery("SELECT factname,monval FROM tsi where frm='"+p+"'"); //IN('"+p+"',"+"'"+f+"',"+"'"+t+"')"); while( { a = rs1.getString("factname"); b= rs1.getString("monval"); //c= rs.getString("mon"); rows1++; }System.out.println(rows1); rs2=st.executeQuery("SELECT monval FROM tsi where frm='"+f+"'"); while( { b= rs2.getString("monval"); rows2++; }System.out.println(rows2);/*// data2=new Object[rows2][1];int i2=0; rs2=st.executeQuery("SELECT monval FROM tsi where frm='"+f+"'"); for(int i1=0;i1
Updating Database by editing jtable   (162 Views)
all, I am new to java and i have a problem which i want to resolve. I recently saw a code which basically lists the values of a database in a jtable, so i modified it and used it in my own app. The problem which i have now come across is the updating of the database by editing the jtable. I have no idea how to do this, the only thing i know is that i have to call an event like firecellupdated but i dont know how to call it and what to call in it and also where to call it. Can anyone help me on this issue. Any help would be appreciated. Harry. Note: Here is the listing code in case you require it // Connect to an MySql Database String driver = "com.mysql.jdbc.Driver"; // String url = "jdbc:odbc: "; // if using ODBC Data Source name String url = "jdbc:mysql://localhost:3306/tpos"; String userid = "root"; String password = "root"; Class.forName( driver ); Connection connection = DriverManager.getConnection( url, userid, password ); // Read data from a table pstat = connection.prepareStatement("Select * from supplier where SupplierId="); pstat.setString(1,search); //String sql = "Select * from supplier where SupplierId="; //Statement stmt = connection.createStatement(); ResultSet rs = pstat.executeQuery(); ResultSetMetaData md = rs.getMetaData(); int columns = md.getColumnCount(); // Get column names for (int i = 1; i
Jbutton inside a jtable wont fire action   (186 Views)
Hi I have a big problem...Im trying to fire an action for a button inside a table, the problem....the button wont fire anything.... I just copyed a jtable button example and adapted it to my model. I hope you can help me , thanks a lot! the editor import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.DefaultCellEditor; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JOptionPane; import javax.swing.JTable; public class ButtonEditor extends DefaultCellEditor { protected JButton button; private String label; private boolean isPushed; public ButtonEditor(JCheckBox checkBox) { super(checkBox); button = new JButton(); button.setOpaque(true); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println(label + ": Ouch!"); fireEditingStopped(); } }); } public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { if (isSelected) { button.setForeground(table.getSelectionForeground()); button.setBackground(table.getSelectionBackground()); } else { button.setForeground(table.getForeground()); button.setBackground(table.getBackground()); } label = (value == null) "" : value.toString(); button.setText(label); isPushed = true; return button; } public Object getCellEditorValue() { if (isPushed) { // // JOptionPane.showMessageDialog(button, label + ": Ouch!"); System.out.println(label + ": Ouch!"); } isPushed = false; return new String(label); } public boolean stopCellEditing() { isPushed = false; return super.stopCellEditing(); } protected void fireEditingStopped() { super.fireEditingStopped(); } }
display all data from database into jtable   (153 Views)
i want to display all data from database into Jtable but my some cell consist of more characters of data because of which we have to scroll jtable a lot so i thought of displaying all data in jtextarea(by displaying it in nextline by using("\n")where ever necessary ) & then insert jtextarea in each cell of jtable but i dont know code please post a code which would help me
jtable column size   (168 Views)
i have a jtable,i want to have all columns Width to be the size of contents in rows. if anything added in row then the column width should increase to fit that value. any suggestion please.
printing a jtable   (339 Views)
I've got a swing JTable of about 20 rows ans 40 columns that I want to print on paper. I tried the table.print() method but that doesn't work, I just get one big empty cell on the paper. I tried an example from another site and that one works perfectly ( Does anyone know what's going wrong Is my table too large for the paper and do I need to resize it, and if so how
inserting jtable into database   (209 Views)
hi friends..i m using javax.swing.JTable..with has three columns..i want to insert it into the mysql database.can i insert whole table in one column of database..please help me.. i m new to usiing the swings components
jtree to jtable (need help in coding)   (137 Views)
Hai all, i was build an jtree from an xml,now for each node there are child elements and the child elements consists of static and dynamic fields,when i select a node in the jtree the child elements should be displayed in jtable format (and one more thing is that my tree consists of 1 supernode and it consists of 4 subnodes and each subnode consists of 3 child nodes).can anyone suggest or give a code to display jtable from jtree. and i should able to edit the values and save to jtree as well as jtable.
how run tim data in jtable or show data in jtable from my database table   (177 Views)
i use DefaultTableModel. or swing jtable some body give me idea i use dumy class and use getColumnClass() and isCellEditable() class for modify the swing defult jtable or swing jtable give class because swing jtable give me defult data that read only but i want show data in jtable form my database table i change the title of table form give propery bu i have lot of row how i run time or dynamicly give data to jtable form my database table in jtable such as my table have data this type sname sno class address marks fahim 34 4 xxxx 545 aamir 43 4 ljfd 55 kashif 33 5 gd 444 and swing defult jtable give me this type data private String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"}; private Object[][] data = { {"Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false)}, {"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)}, {"Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false)}, {"Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true)}, {"Philip", "Milne", "Pool", new Integer(10), new Boolean(false)} }; or null data please give me ida how i show my database table data in jtable and how i set the jpanel location such as setlocation(12,14,3,5) but this code not give me right result please give right code
get correct values from sorted jtable   (128 Views)
hi! maybe you can help me get the correct row value from a sorted jtable i am able to be a value using getValueAt() but when i sort the table the value i get dont match the one on display. i believe there is an extra step to retrieve the real row, but i dont know how.
Removing a jtable from a jpanel/Changing the table   (151 Views)
.. I've written this code, which creates a table with a scrollpane, and loads the results of a search, when a button is pressed. The problem is that each time i press the button a new jtable is created. How can i make it either: a) refill the same table b) remove the table and make another one which displays the new results. My code: searchBt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pd.contains(qTxt1.getText(),true); System.out.println(pd.dictSearchStore.size()); if (pd.toObject()!= null && pd.toObject().length!=0) { JTable resTable = new JTable(pd.toObject(),tableTitles); JScrollPane scrollPane = new JScrollPane(resTable); resTable.setPreferredScrollableViewportSize(new Dimension(170, 160)); panel.add(scrollPane); panel.validate(); } } });
jtable and jscrollpane question   (152 Views)
hey, I have a JTable in a JScrollPane. My application is designed to have this table take up most of the screen. Sometimes the table has hundreds of rows of data in it and everything works well. However, sometimes it only has three rows in it and it looks very bad inside of the scrollPane. I would like my table to be full screen all the time regardless of the actual number of rows of data it has. Is there an easy way to do this or do I have to add "blank" rows to my table whenever I detect this condition
jtable, table model, column headers   (130 Views)
Dear all, I am using jbuilder 10 for an application and I have bumped on a glitch. I create my own tablemodel (which inherits from the AbstractTableModel) do the necessary work (implementing the abstract methods) and I also override getColumnName method. However, when the application starts no column headers appear (even though when I pass my tabled model in teh JTable constructor getColumnName is called). At first I believed that I had made a mistake with my table model class but when I used the FileTableModel class from O'Rilley's JFC book same thing happened. Does anyone have any idea why this is happening thanks in advance dimitris ps this is my table model -------------------------------------------------------------------------- package testapp; import javax.swing.table.*; import java.util.Vector; public class DataModel extends AbstractTableModel { protected String[] columnNames; protected Vector data; protected Class[] columnClasses = new Class[] {String.class, Boolean.class}; public DataModel(Vector data, String[] columnNames) { = data; this.columnNames = columnNames; fireTableStructureChanged(); } public int getRowCount() { return data.size(); } public int getColumnCount() { return columnNames.length; } public Object getValueAt(int rowIndex, int columnIndex) { switch (columnIndex) { case 0: return data.elementAt(rowIndex); case 1: return (Object) new Boolean(true); default: return null; } } public void removeValueAt(int rowIndex, int columnIndex) { data.removeElementAt(rowIndex); fireTableRowsDeleted(rowIndex, columnIndex); } public void insertElementAt(Object o, int index){, index); fireTableRowsInserted(index, index); } public void append(Object o) {; fireTableRowsInserted(data.size()-1, data.size()-1); } public String getColumnName(int columnIndex) { return columnNames[columnIndex]; } public Class getColumnClass(int col) { return columnClasses[col]; } } ---------------------------------------- and this is how i call it from the mainFrame Vector data = new Vector(); String[] columnNames = new String[] {"column 1", "column 2"}; DataModel dm = new DataModel(data, columnNames) JTable table = new JTable(dm) , yeap that was it. I needed either a scrollpane or explicitly get the headers there. Thanx for the help. good day
Can we set an image in a cell of a jtable.   (143 Views)
[color=red][/color][size=24][/size][size=18][/size][size=24]Can we set an image in a cell of a jtable.[/size]
update rows in jtable   (153 Views)
I can update rows in database, but in jTable I see the changes only after I close the application and rerun it. What should I do This is my code: private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { try { Class.forName("org.apache.derby.jdbc.ClientDriver"); Connection con = (Connection) DriverManager.getConnection("jdbc:derby://localhost:1527/Proiect","aneresia","aneresia"); int rowNumber=jTable1.getSelectedRow()+1; // Statement stmt1 = con.createStatement(); // int rowsUpdated; con.setAutoCommit(false); stmt1.executeUpdate("Update Carti set nume_autor='"+jTextField2.getText()+"' , pren_autor='"+jTextField3.getText()+"', nume_carte='"+(String)jTextField4.getText()+ "' , nr_car_stoc="+jTextField5.getText()+" ,editura='"+jTextField6.getText()+"' , an_aparitie="+jTextField7.getText()+ " , pret_v="+jTextField8.getText()+" where cod_carte="+rowNumber); model.fireTableRowsUpdated(rowNumber, rowNumber); con.commit(); con.close(); } catch (SQLException ee) { ee.printStackTrace(); } catch (Exception f) { } }