Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

HELP in JTable

  Asked By: Demyan    Date: Sep 10    Category: Java    Views: 821
  

I need to load some date in a JTable wich already exists in the
JInternalFrame component, the problem is when I try to put these data from
the ResultSet in the JTable it does not work, I cant figure out what I am
doing wrong and I must that I´ve tryed a lot, please have a look in my code
and in the execepion I´ve got and give any idea to fix this:

the code:
tbValores.removeAll(); // <<<<<=========== JTable
Vector linha = new Vector();
dados.clear();//<<========== data lines to the JTable

rs = st.executeQuery("SELECT * FROM VALORTARIFAS WHERE
CODTABELA='"+textoCodigo.getText()+"'");
while (rs.next())
{
System.out.println(rs.getString("CODTABELA")+" -
"+rs.getString("NUMLINHA")+" - "+rs.getString("TIPOTARIFA")+" -
"+rs.getString("QUANTINICIO")+" - "+rs.getString("QUANTFINAL")+" -
"+T.paraMoeda(rs.getString("VALORFAIXA")));

linha.addElement(rs.getString("CODTABELA"));
linha.addElement(rs.getString("NUMLINHA"));
linha.addElement(rs.getString("TIPOTARIFA"));
linha.addElement(rs.getString("QUANTINICIO"));
linha.addElement(rs.getString("QUANTFINAL"));
linha.addElement(T.paraMoeda(rs.getString("VALORFAIXA")));
dados.addElement(linha);
//modTabValores.addRow(linha);
linha.clear();// <======== IF I DONT USE THIS LINE IT LOADS, BUT JUST
THE FIRST VALUE FOUND IN THE
// RESULTSET, OTHERWISE I GOT THE EXCEPTION:
// java.lang.ArrayIndexOutOfBoundsException: 0
>= 0
}
//modTabValores = new DefaultTableModel(dados,colunas);
//tbValores.setModel(modTabValores);
tbValores.repaint();

the execution and the exception:
2 - 1 - Q - 0.000 - 50.000 - R$ 12,00
2 - 2 - Q - 51.000 - 100.000 - R$ 13,00
2 - 3 - Q - 101.000 - 200.000 - R$ 14,00
2 - 4 - Q - 201.000 - 500.000 - R$ 16,00
java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Vector.java:427)
at
javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:618)
at javax.swing.JTable.getValueAt(JTable.java:1759)
at javax.swing.JTable.prepareRenderer(JTable.java:3675)
at
javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:1149)
at
javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1051)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:974)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)
at javax.swing.JComponent.paintComponent(JComponent.java:537)
at javax.swing.JComponent.paint(JComponent.java:804)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JViewport.paint(JViewport.java:707)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:552)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:552)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at
javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4742)
at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4688)
at javax.swing.JComponent._paintImmediately(JComponent.java:4632)
at javax.swing.JComponent.paintImmediately(JComponent.java:4464)
at
javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:410)
at
javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQu
eueUtilities.java:117)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:443)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.ja
va:191)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
:144)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)
java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Vector.java:427)
at
javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:618)
at javax.swing.JTable.getValueAt(JTable.java:1759)
at javax.swing.JTable.prepareRenderer(JTable.java:3675)
at
javax.swing.plaf.basic.BasicTableUI.paintCell(BasicTableUI.java:1149)
at
javax.swing.plaf.basic.BasicTableUI.paintCells(BasicTableUI.java:1051)
at javax.swing.plaf.basic.BasicTableUI.paint(BasicTableUI.java:974)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:142)
at javax.swing.JComponent.paintComponent(JComponent.java:537)
at javax.swing.JComponent.paint(JComponent.java:804)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JViewport.paint(JViewport.java:707)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:552)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:552)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JViewport.paint(JViewport.java:707)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at javax.swing.JComponent.paint(JComponent.java:813)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:552)
at javax.swing.JComponent.paintChildren(JComponent.java:643)
at
javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4742)
at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4688)
at javax.swing.JComponent.paint(JComponent.java:794)
at
java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
at
sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
at
sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
at java.awt.Container.paint(Container.java:1268)
at sun.awt.RepaintArea.paint(RepaintArea.java:177)
at
sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
at java.awt.Component.dispatchEventImpl(Component.java:3587)
at java.awt.Container.dispatchEventImpl(Container.java:1582)
at java.awt.Window.dispatchEventImpl(Window.java:1586)
at java.awt.Component.dispatchEvent(Component.java:3368)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.ja
va:191)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
:144)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)


PS. My Locale is ("pt","BR")

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on HELP in JTable Or get search suggestion and latest updates.




Tagged: