Jump to content

Hi!

 

I am programming a program which lets you safe and load back values from tables.

The save works but I am stuck on the loading.

 

You write your values into the table, by clicking on Save your tablevalues save into a chosen .txt file.

The onLoad(...) gets the values from a txt file and converts it back into the table(s).

 

Here is the whole code: http://pastebin.com/zEkbu52j

 

 

Here is the onLoad(...):

private void onLoad(java.awt.event.ActionEvent evt) {                            mHeadgear = (DefaultTableModel) tbHeadgear.getModel();            JFrame parentFrame = new JFrame();     JFileChooser fileChooser = new JFileChooser();    fileChooser.setDialogTitle("Specify a file to load");       FileNameExtensionFilter filter = new FileNameExtensionFilter("TEXT FILES", "txt", "text");    fileChooser.setFileFilter(filter);        int userSelection = fileChooser.showOpenDialog(parentFrame);    FileWriter fw = null;                if (userSelection == JFileChooser.APPROVE_OPTION)     {        File fileToLoad = fileChooser.getSelectedFile();                        try {            fw = new FileWriter(fileToLoad.getAbsoluteFile());        } catch (IOException ex) {            JOptionPane.showMessageDialog(rootPane, ex.getLocalizedMessage());        }                BufferedReader br = new BufferedReader(fw);                        String inputLine;        try         {            inputLine = br.readLine();            while(inputLine != null)            {                StringTokenizer tokenizer = new StringTokenizer(inputLine);                mHeadgear.setDataVector(); //How can I read the text correctly?            }        } catch (IOException ex) {            JOptionPane.showMessageDialog(rootPane, ex.getLocalizedMessage());        }                try {            bw.close();        } catch (Exception ex) {            JOptionPane.showMessageDialog(rootPane, ex.getLocalizedMessage());        }    }    }               

Thanks for helping in advance :)

"Of course, it is completely normal to have a GPU at 90°c all the time <_<"  -Arty, 2014

 

Ex-Mainframe Dev, Ex-Client Service, Ex-Sysadmin, Ex-Network Engineer | InfoSec Enjoyer & Practitioner

 

 

Love you all - thanks for helping me! ^_^

 

Link to comment
https://linustechtips.com/topic/263299-java-get-table-data-into-jtable/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×