Daniel Roach

Greenhorn
+ Follow
since Mar 12, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Daniel Roach

I have an editable JTable which uses a class which extends the AbstractTableModel as the data model. I have methods which save the data from the model into a file. How can I be sure that all the changes to the JTable are reflected in the model? I am using the DefaultCellEditor to edit the cells.
Any help would be very much appreciated.
22 years ago
oops kyle, sorry about misspelling your name
why is it both and not just the class specified in web.xml?
cheers

Originally posted by Kyle Tang:
both



Kylie
why is it both and not just the class specified in web.xml?
cheers
Dan
I have a application based on a Jtable. A custom model class has been created by extending AbstractTableModel. Columns are created individually, from an input file, and then added to table. The Table is displayed in an JInternalFrame. I want to be able to add columns. I have added a menu, which adds the new data to the data model, but as AutoCreateColumnsFromModel is false, FireTableStructureChanged does not add in the new column. I have added a new TableColumn object to the table, but can't get the table to change. I have tried calling doLayut and repaint on the table but with no success. Does anyone have any suggestions?
Thanks in advance.
Daniel
22 years ago
I have a 'spreadsheet' like application in which the user selects a file, using JFileChooser, which is passed to the constructor of a class extending abstract table model. This file is read and then used to populate a Jtable which is then displayed in an internal frame. The user can change the values in the table, and I need to be able to save these changes. I have a save file menu item, which chooses a file to save, but from this method I am unable to access the ArrayLists which hold the data in the table model. I wanted to convert these into strings and then save the file. Does anyone have any ideas to solve this, I know there must be an easy answer.
Thanks in advance
Dan
22 years ago
Thanks for the advice.
Here is the code I have been using. The problem still exists though, any other suggestions.
Thanks in advance
Dan
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import javax.swing.*;
import javax.swing.table.*;
import java.io.*;
import java.util.*;
import javax.swing.event.*;
/**
build a table from a table model.
*/
public class DanSpreadII
{
public static void main(String[] args)
{
JFrame frame = new DanSpreadFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
/**
This frame contains the DanSpread table.
*/
class DanSpreadFrame extends JFrame
{
public DanSpreadFrame()
{
super("SpreadSheet");
setSize(600,600);
JMenuBar menuBar = createMenuBar();
setJMenuBar(menuBar);

}
protected JMenuBar createMenuBar()
{
JMenuBar menuBar = new JMenuBar();
JMenu mFile = new JMenu("File");
JMenuItem open = new JMenuItem("Open file");
open.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
JFileChooser chooser = new JFileChooser();
int r = chooser.showOpenDialog(DanSpreadFrame.this);
if (r != JFileChooser.APPROVE_OPTION) return;
File f = chooser.getSelectedFile();

TableModel model = new DanSpreadData(f);
JTable table = new JTable(model);
JScrollPane pane = new JScrollPane(table);
table.setAutoResizeMode(table.AUTO_RESIZE_OFF);
table.setPreferredScrollableViewportSize(new Dimension(150,150));
frame.getContentPane().add(pane);
}
});
mFile.add(open);
mFile.addSeparator();
JMenuItem exit = new JMenuItem("Exit");
exit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
});
mFile.add(exit);
menuBar.add(mFile);
return menuBar;
}
private static final int WIDTH = 1800;
private static final int HEIGHT = 300;
}
22 years ago
I have an application that uses a JFrame. It's constructor creates a menubar. From the actionperformed method, a filechooser is used to select a file, which is passed to the constructor of a Tablemodel class, which then
creates a table in a scrollpane. How do I get the table to be visible.
getContentPane().add(pane); does not work. Is there a better approach
Thanks in advance
22 years ago
Thanks Jagan it worked perfectly
22 years ago

Originally posted by Jagan Mohan Reddy:
Hi,
Think the below sample code might solve ur problem..
table = new JTable(3,300);
table.setAutoResizeMode(table.AUTO_RESIZE_OFF); // Used to set the Auto resize in the off mode..
scrollPane = new JScrollPane(table);
table.setPreferredScrollableViewportSize(new Dimension(50,50));
getContentPane().add(scrollPane);
Regards,
Jagan Mohan Reddy

22 years ago
I have created a large Jtable (300 columns), how do I obtain a scrollbar so I can view columns which do not fit onto the JScrollpane?
Thanks
22 years ago