473,480 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how do i update a jtextarea in a GUI, with only new rows in an excel file

112 New Member
Hi,
I need help updating my jtextarea.
I am reading rows from an excel file and after it is done writing to the jtextarea, the excel file is rewritten with the old rows plus new rows and then again, the jtextarea is recreated with the rows from the excel file.

What i would like to do is keep the content in the jtextarea and only add to the bottom with the newest rows in the excel file. The excel file is always rewritten, but they are sorted by time so the newest rows are always at the bottom.

Below is the code that i have that creates the gui, along with the text area.

Expand|Select|Wrap|Line Numbers
  1. public JFrame baseFrame;
  2.     private JButton highButton = new JButton("HIGH");
  3.     private JButton medButton = new JButton("MEDIUM");
  4.     private JButton lowButton = new JButton("LOW");
  5.     private ButtonGroup group;
  6.  
  7.     public JTextArea area = new JTextArea(17, 47);
  8.  
  9.  
  10.  
  11.     DesktopSHMTranslator translator;
  12.  
  13.     public DesktopSHMGUI() throws Exception
  14.     {
  15.         baseFrame = new JFrame("SHM Alarms");
  16.         baseFrame.setSize(700,500);
  17.  
  18.         baseFrame.getContentPane().setLayout(new BorderLayout());
  19.  
  20.  
  21. //        area.setLineWrap(true);
  22.  
  23.  
  24.         area.setWrapStyleWord(true);
  25.         area.setBorder(BorderFactory.createEmptyBorder(45, 45, 45, 45));
  26.         JScrollPane scrollPane = new JScrollPane(area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  27.  
  28.  
  29.         JPanel textPanel = new JPanel();
  30.         textPanel.setLayout(new FlowLayout());
  31.         textPanel.add(scrollPane, BorderLayout.CENTER);
  32.  
  33.  
  34. //        panel.add(highButton);
  35. //        panel.add(medButton);
  36. //        panel.add(lowButton);
  37.  
  38.         JPanel buttonPanel = new JPanel();
  39.         buttonPanel.add(highButton, BorderLayout.WEST);
  40.         buttonPanel.add(medButton, BorderLayout.CENTER);
  41.         buttonPanel.add(lowButton, BorderLayout.EAST);
  42.  
  43.  
  44.         highButton.addActionListener(this);
  45.         highButton.setActionCommand("high");
  46.         medButton.addActionListener(this);
  47.         medButton.setActionCommand("med");
  48.         lowButton.addActionListener(this);
  49.         lowButton.setActionCommand("low");
  50.  
  51.  
  52.         baseFrame.getContentPane().add(textPanel, BorderLayout.CENTER);
  53.         baseFrame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
  54.  
  55.         baseFrame.addWindowListener(new CloseWindow());
  56.  
  57.         translator = DesktopSHMTranslatorHome.createDesktopSHMTranslator(this);
  58.  
  59.         baseFrame.setVisible(true);
  60.  
  61.     }
  62.  
Here is the code where i write to the jtextarea:

Expand|Select|Wrap|Line Numbers
  1. private void contentReading(FileInputStream fileInputStream) {
  2.         // TODO Auto-generated method stub
  3.  
  4.         WorkbookSettings ws = null;
  5.         Workbook workbook = null;
  6.         Sheet s = null;
  7.         Cell rowData[] = null;
  8.         int rowCount = '0';
  9.         int columnCount = '0';
  10.         DateCell dc = null;
  11.         int totalSheet = 0;
  12.  
  13.  
  14.         try {
  15.             ws = new WorkbookSettings();
  16.             ws.setLocale(new Locale("en", "EN"));
  17.             workbook = Workbook.getWorkbook(fileInputStream, ws);
  18.  
  19.             totalSheet = workbook.getNumberOfSheets();
  20.  
  21.             //Getting Default Sheet i.e. 0
  22.             s = workbook.getSheet(0);
  23.  
  24.             //Reading Individual Cell
  25. //            getHeadingFromXlsFile(s);
  26.  
  27.  
  28.             rowCount = s.getRows();
  29.             columnCount = s.getColumns();
  30.  
  31.             for (int i = 0; i < rowCount; i++) {
  32. //            for (int i = DesktopSHMTranslator.startOfRow; i < rowCount; i++) {
  33.                 //Get Individual Row
  34.                 rowData = s.getRow(i);
  35.                 if (rowData[0].getContents().length() != 0) { // the first data column must not null
  36.                     for (int j = 0; j < columnCount; j++) {
  37.                         if(j==0){
  38.                             area.setFont(new Font("sansserif", Font.BOLD, 12));
  39.                             area.scrollRectToVisible(new Rectangle(0,area.getHeight()-2,1,1));
  40.                             area.append(rowData[j].getContents() + " --- ");
  41.                         }
  42.                         else if(j==1)
  43.                             area.append(rowData[j].getContents() + " --- ");
  44.                         else if(j==2)
  45.                             area.append(rowData[j].getContents() + " --- ");
  46.                         else if(j==3)
  47.                             area.append(rowData[j].getContents() + " --- ");
  48.                         else if(j==4)
  49.                             area.append(rowData[j].getContents() + " --- ");
  50.                         else if(j==5)
  51.                             area.append(rowData[j].getContents() + " --- ");
  52.                         else if(j==6)
  53.                             area.append(rowData[j].getContents() + " --- ");
  54.                         else if(j==7)
  55.                             area.append(rowData[j].getContents() + "\n");
  56.                     }
  57.                 }
  58.             }
  59.  
  60.             workbook.close();            
  61.         } catch (IOException e) {
  62.             System.out.println("YOU ARE IN IOEXCETPION in CONTENTREADING");
  63.             e.printStackTrace();
  64.         } catch (BiffException e) {
  65.             System.out.println("YOU ARE IN BIFFEXCEPTION in CONTENTREADING");
  66.             e.printStackTrace();
  67.         }
  68.     }
  69.  

Basically right now, every time the excel file is read and the jtextarea is written to, it rewrites the whole excel file which takes some time and it shows each line by line being written to. I want it so that the content in the jtextarea is still there and the only lines that are added are lines that are new to the excel file that are not already in the jtextarea.

thanks for the help guys!!
Apr 28 '11 #1
0 1449

Sign in to post your reply or Sign up for a free account.

Similar topics

6
18815
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
1
2448
by: Luis Esteban Valencia | last post by:
Hello Everyone, Iam an intermediate ASP.Net programmer and iam facing a challenging task. I have a table in MS-SQL server database called 'Members'. The table has following fields... ...
1
1640
by: Moomin Ma | last post by:
I have create a excel file with 2 columns and 2 rows for demonstration. The excel file is then opened by ms access and therefore a mdb file was created. The mdb file showing the correct linkage...
3
3269
by: RJN | last post by:
Hi I've a template excel file which has all the calculations defined. There are certain input values to be entered which gives a lot of output to the user. I don't want to expose the excel sheet...
1
1142
by: Esmael | last post by:
Hi... Can anyone help me... on how to share an Excel File...? I Have 2 excel file... one is the source(the program just read the data her) and a template.(Program open this and transfer the...
1
1113
by: reddyoggu | last post by:
Hi, I am developing a web application, which is supposed to update an already existing excel file. This excel file contains 2 charts too. Could u help me in this regard?. Thanks in advance.
1
2875
by: chrspta | last post by:
I am new to Visual basic. I need a program using VB6 that converts txt files to excel file.Description is in the below: The form should have the Drive list, Dir list, file list and cmdConvert...
5
7279
by: vimal.424 | last post by:
Hi......all.... can any body tell me how can we upload excel file & send the excel file data in database. I;m not able to do........please help me...... thanks in advance
0
1080
by: qfchen | last post by:
I try to import data from an excel file, then save the data to a database, however, some cell always empty when read, whose cell combine with digit and alphabet, eg. "92FE0". below are the VB code ...
6
6335
by: srikanya | last post by:
Hi, I have a database with 10 tables and I want to export all table data into excel file.But there should be only one excel file with different sheets in it, each containing different tables data.
0
7048
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6911
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7050
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
6966
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4787
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2999
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2988
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
564
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.