dcsimg
Creating Tabs using button in Visual Editor
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nick_Carter
Posted On:   Friday, January 12, 2007 05:14 AM

i m trying to write a multi tabs text reader, how ever there are java.lang.NullPointerException appear when i open using visual editor, anyone can pls tell me how to solve this? import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem;    More>>

i m trying to write a multi tabs text reader, how ever there are java.lang.NullPointerException appear when i open using visual editor, anyone can pls tell me how to solve this?






import java.io.BufferedReader;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;


import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.FileDialog;

import org.eclipse.swt.widgets.Shell;

import org.eclipse.swt.graphics.Point;

import org.eclipse.swt.custom.CTabFolder;

import org.eclipse.swt.custom.CTabItem;

import org.eclipse.swt.SWT;

import org.eclipse.swt.graphics.Rectangle;

import org.eclipse.swt.widgets.Button;

import org.eclipse.swt.widgets.Text;

public class GUI {


private Shell sShell = null; // @jve:decl-index=0:visual-constraint="56,11"

private CTabFolder cTabFolder = null;

private Integer tabCounter = 0; // @jve:decl-index=0:

private Button bOpen = null;

private Text textArea = null;



public static void main(String [] args) {

Display display = Display.getDefault();

GUI thisClass = new GUI();

thisClass.createSShell();

thisClass.sShell.open();

while (!thisClass.sShell.isDisposed()) {

if (!display.readAndDispatch())

display.sleep();

}

display.dispose();

}


private void createSShell() {

sShell = new Shell();

sShell.setLayout(null);

createCTabFolder();

sShell.setSize(new Point(498, 204));

bOpen = new Button(sShell, SWT.NONE);

bOpen.setBounds(new Rectangle(19, 121, 46, 34));

bOpen.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {

public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {

readfile();

}

});

}


private void createCTabFolder() {

cTabFolder = new CTabFolder(sShell, SWT.None);

cTabFolder.setBounds(new Rectangle(19, 7, 455, 105));

}


private void readfile() {

FileDialog dialog = new FileDialog(sShell, SWT.OPEN);

String result = dialog.open();

if (result != null) {

File f = new File(result);

try {

BufferedReader br = new BufferedReader(new FileReader(f));

StringBuffer buff = new StringBuffer();

String line = br.readLine();

while (line != null) {
buff.append(line + "
");

line = br.readLine();

}

CTabItem filetab = new CTabItem(cTabFolder, SWT.NONE);

filetab.setText(tabCounter.toString());

tabCounter++;

textArea = new Text(cTabFolder, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);

filetab.setControl(textArea);

textArea.setText(buff.toString());

br.close();

} catch (FileNotFoundException e1) {

e1.printStackTrace();

} catch (IOException e1) {

e1.printStackTrace();

}

}

}


}

   <<Less
About | Sitemap | Contact