Board index » jbuilder » JTable

JTable


2004-11-26 04:11:04 AM
jbuilder13
Hello!!
I want to know how i can modify a JTable (insert a row for example) when i
click on a button.
When I try to change JTable property, my application don't display the
updated JTable. I must resize the frame to display the updated JTable.
Thanks.
 
 

Re:JTable

On 11/25/2004 at 3:11:04 PM, Sowamber Alan wrote:
Quote
I want to know how i can modify a JTable (insert a row for example) when
i click on a button.
You need to update the TableModel for the table.
Quote
When I try to change JTable property, my application don't display the
updated JTable. I must resize the frame to display the updated JTable.
It is hard to tell what you are doing wrong, since you do not show what
you are doing. It seems likely that the model is not firing the
appropriate table events when you make the change. This is probably
because you are not updating the model properly.
--
Regards,
John McGrath [TeamB]
---------------------------------------------------
Before sending me e-mail, please read:
www.JPMcGrath.net/newsgroups/e-mail.html
 

Re:JTable

HI -
I have a jtable that uses two custom default cell editors to create combo
boxes for two of the the 4 columns. If the user selects another value from
either of the combo boxes i want to know that so i can indicate a save must
occur. I'm not sure what event i should listen to? Does any one have any
suggestions?
Thanks in advance.
Erica
 

{smallsort}

Re:JTable

I have created a JTable. However if my table gets too big or if i
resize the application window, the horizontal scrollbar does not appear
at all. The vertical scrollbar works fine. I'm using eclipse. Heres a
copy of the code i'm working with:
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.ScrollPaneConstants;
import java.awt.*;
import java.awt.event.*;
public class SimpleTable extends JFrame {
public SimpleTable() {
super("Personnel");
Object[][] data = {
{"Thomas", "Albanese", "Engineer",
"Development", new Integer(10)},
{"Laura", "Bates", "Administrator",
"Benefits", new Integer(4)},
{"Susan", "Carson", "Director",
"Marketing", new Integer(12)},
{"William", "Delancy", "Instructor",
"Support", new Integer (6)}
};
String[] columnNames = {"First Name",
"Last Name",
"Job Title",
"Department",
"Service (yrs)"};
JTable perstab = new JTable(data, columnNames);
perstab.setPreferredScrollableViewportSize(
new Dimension(500, 65));
JScrollPane scrollPane = new JScrollPane(perstab,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
getContentPane().add(scrollPane,BorderLayout.CENTER);
}
public static void main(String[] args) {
SimpleTable frame = new SimpleTable();
frame.pack();
frame.setVisible(true);
}
}