Results 1 to 9 of 9
- 09-21-2011, 06:24 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 7
- Rep Power
- 0
Problem with JTable - only some rows are displayed
Hello,
I have an annoying problem. I use a JTable and a DefaultTableModel but I also tried customized models created by "extends DefaultTableModel" (with and without super()) and "extends AbstractTableModel".
I am giving an array to it (String[][] with 315 lines ) and there are only 28 of 315 entries represented.
I did not change any default option despite of "setPreferedsize" and "setVisible" and "setOpaque".
Of course I verified the array created as a result of reading an excel file: Even in the model - giving it to the super constructor - it has exactly the size of 315 lines.
As I print all rows simultaneously in the output there is no error of any type loading the data (anyway there would be no data at all in my table if this was the case , as I experienced several times.)
By debugging I cannot find any error: all data are as they should be, except for the representation of the data. As this happens also in the defaultTableModel I am getting a little bit desperate because I begin to doubt in Java...
I might give the relevant parts of the code here but I don't think this will help:
I have 18 columns in my table. I verified the columncount by System.out.print in the function getRowCount() in the model. Everything ok. I deleted a number of columns or rows (only 28, all from 1 to 74 etc.) in the file : no change: 28 lines starting from the first line not deleted are given. At any point I could imagine the right number of rows of the String [][] (315) is indicated.Java Code:provcedure init() of the panel class (extends JPanel): public void init(Dimension d){ GridBagLayout gbl = new GridBagLayout(); this.setLayout(gbl);int textgrösse = 20; int kbeginSpalte = 0;int kbeginZeile = 0; data = new String[][] {{" ", " "," "}} ; /// dummy for table to show jtal = new JTable(); //BasicTable(); column_names = getHeadersFromExcelTable(""); jtal.setModel(new BasicTableModel(data,column_names));/// tried also DefaultTableModel BasicTableRenderer renderer = new BasicTableRenderer(jtal); jtal.setDefaultRenderer(Object.class, renderer); jtal.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); //JList rowHeader = new JList(new RowHeaderListModel(data.length)); //I verified that this is not the problem by commenting it out //rowHeader.setFixedCellWidth(50); // rowHeader.setFixedCellHeight(jtal.getRowHeight()+ jtal.getRowMargin()+ /// jtal.getIntercellSpacing().height); // rowHeader.setCellRenderer(new RowHeaderRenderer(jtal)); JTableHeader colheader = jtal.getTableHeader(); //colheader.setBackground(Color.gray); jtal.setRowHeight(jtal.getRowHeight()+ jtal.getRowMargin()+ jtal.getIntercellSpacing().height); colheader.setOpaque(true); Dimension dsc = new Dimension(800,500); jtal.setPreferredSize(dsc);JScrollPane scr1 = new JScrollPane();//ScrollPane anlegen // scr1.setRowHeaderView(rowHeader); scr1.setPreferredSize(new Dimension(810,510)); scr1.add(jtal); scr1.setViewportView(jtal); btnLaden = new BasicButton("Messdaten Laden", textgrösse); btnLaden.setVisible(true); btnLaden.addActionListener(new ActionListener() { private String messDateiPfad; @Override public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); File f = null; try { f = new File(new File(".").getCanonicalPath()); } catch (IOException ex) { } fc.setCurrentDirectory(f);int returnVal = 0; returnVal = fc.showOpenDialog(btnLaden); if (returnVal == JFileChooser.APPROVE_OPTION) { File thefile = fc.getSelectedFile(); messDateiPfad = thefile.getPath(); } column_names = getHeadersFromExcelTable(messDateiPfad); data = fillTable( messDateiPfad); //jtal=new BasicTable(data,column_names); jtal.setAutoResizeMode(4); BasicTableModel btm =new BasicTableModel(data,column_names); jtal.setModel(btm); SwingUtilities.updateComponentTreeUI(jtal); } }); this.addComp(gbl, scr1, kbeginSpalte,kbeginZeile,4,5,0,0,GridBagConstraints.NONE, GridBagConstraints.NORTHWEST); this.addComp(gbl, btnLaden, kbeginSpalte,kbeginZeile+6,4,1,0,0,GridBagConstraints.NONE, GridBagConstraints.NORTHWEST); //// addComp is the procedure given in "Java ist auch eine Insel": Layout GridBagLayout } public String[][] fillTable(String messDateiPfad) { String[][] result = {{" ", " ", " "}} ; ReadExcel rxl = new ReadExcel(); rxl.setInputFile(messDateiPfad); try { data = rxl.read(); result = data; } catch (IOException ex) { Sytem.out.PrintLn("Error") } return result; } private String[] getHeadersFromExcelTable(String messDateiPfad) { String[] result = {"Aktiv ?", "Quelle", "Bezeichnung"} ; ReadExcel rxl = new ReadExcel(); if (!(messDateiPfad.equalsIgnoreCase(""))) { rxl.setInputFile(messDateiPfad); try { result = rxl.readHeaders(); } catch (BiffException ex) { } catch (IOException ex) { } } return result; } } /// the returned String [] [] data returned exactly all 315 lines and 18 columns of the Excel file. /// I will not give the code here: API JXL 2.8.3 public class BasicTableModel extends AbstractTableModel { public static final long serialVersionUID = 1111111L; private Object [][] daten = null; private Object[] headerNames = null; //private Class columnClasses[] = {String.class, String.class, String.class,Object.class, Object.class}; public BasicTableModel() { headerNames = new Object[1]; } public BasicTableModel(String[] column_names, int i) { headerNames = column_names; for(int j = 0; j< column_names.length;j++) { headerNames[j] = (column_names[j]); } } public BasicTableModel(String[][] data,String[] columnNames) { headerNames = new Object[columnNames.length]; for(int j = 0; j< columnNames.length;j++) { headerNames[j]= columnNames[j]; } daten = new Object[data.length][]; for(int i = 0; i< data.length;i++) { daten[i]= new Object[data[i].length]; for(int j = 0; j< data[i].length;j++) { daten[i][j] = data[i][j]; } } } @Override public int getRowCount() { return this.daten.length; } @Override public int getColumnCount() { return headerNames.length; } @Override public Object getValueAt(int rowIndex, int columnIndex) { return daten[rowIndex][columnIndex]; } }
If I just use DefaultTablemodel and JTable (so no problem which I introduced myself normally) I get the same result: 28 lines, although there is no change in type of data or number of columns with data in those lines.
I use java jdk 1.6.20- Anyway all other jdk's (1.6.27, 1.7.0) are crashing when I try to install them....
If I don't find a solution the entire project will die .....
ThanksLast edited by ThommyW; 09-21-2011 at 09:57 PM. Reason: forgot tags
- 09-21-2011, 06:29 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: Problem with JTable - only some rows are displayed
Put your code in [ code ] tags, otherwise you lose any formatting, making things really difficult to read.
- 09-21-2011, 07:14 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 7
- Rep Power
- 0
Re: Problem with JTable - only some rows are displayed
Sorry, it is the first time since years that I am in a forum. Furthermore tags are hard to find here: there is no symbol anywhere to surround the code by click as usual, it is not clear how to write exactly the tags and there is no indication anywhere (big Letters ?, slash or back slash ?). Or Did I overlook something? Anyway I hope it is better now. I doubt that the code will help much: Last Debugging did not show any problem. Unfortunately to give still more code (eg. reading Excel files with jxl to get the array) would be to much. The big question is how to reproduce this problem without using my whole program....
- 09-21-2011, 07:42 PM #4
Re: Problem with JTable - only some rows are displayed
Moved from "Advanced Java"
db
- 09-21-2011, 07:43 PM #5
Re: Problem with JTable - only some rows are displayed
Do you really write your code without indents? Please go through Code Conventions for the Java(TM) Programming Language: Contents
db
-
Re: Problem with JTable - only some rows are displayed
Agree, you'll want to fix your posted code because right now it is pretty well un-readable.
- 09-22-2011, 01:04 AM #7
Re: Problem with JTable - only some rows are displayed
- 09-22-2011, 03:25 AM #8
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Re: Problem with JTable - only some rows are displayed
I thought I was the only one with this problem. I reported this problem a couple of weeks ago: Missing Markup Buttonsthere is no symbol anywhere to surround the code by click as usual, it is not clear how to write exactly the tags and there is no indication anywhere (big Letters ?, slash or back slash ?). Or Did I overlook something?
@Pete, @Darryl, maybe you guys can follow-up on this. I would hope you have more influence than I do.
- 09-22-2011, 03:27 AM #9
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Similar Threads
-
Jtable rows
By riddhishah28 in forum AWT / SwingReplies: 3Last Post: 02-18-2011, 06:24 AM -
Remove Jtable rows
By anilkumar_vist in forum Advanced JavaReplies: 2Last Post: 09-17-2010, 08:03 AM -
Listening rows in JTable ??
By Stephen Douglas in forum New To JavaReplies: 2Last Post: 04-10-2010, 04:45 PM -
Updating Displayed Table Rows
By raycini in forum JavaServer Faces (JSF)Replies: 2Last Post: 04-20-2009, 08:24 AM -
Deleting All rows in the JTable
By surot in forum New To JavaReplies: 1Last Post: 04-16-2008, 10:44 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks