SWT: Text aus File in scrollbaren Text ausgeben

Demo6_66/

Grünschnabel
Hi,

ich bins mal wieder. ICh hab eine Verstaendnisfrage bezueglich des Text Widgets von SWT.

Ich lasse mir in folgender Klasse einen Text aus einem File in einen String einlesen und gebe diesen in ein Multi Text Widget.

Code:
public final class AboutDialog {
	
	private final static String resourcePic = "pixmaps/aboutPic.png";
	private final static String resourceCredits = "org/gui/text/credits.txt";
	private Image topImage;

	
	public AboutDialog(Shell shell){
		int style = SWT.CLOSE | SWT.APPLICATION_MODAL | SWT.TITLE;
		final Shell aboutShell = new Shell(shell,style);
		Display display = shell.getDisplay();
		
		RowLayout layout = new RowLayout();
		layout.type=SWT.VERTICAL;
		layout.fill=true;
		
		topImage = new Image(display,getClass().getResourceAsStream(resourcePic));
		Label picLabel = new Label(aboutShell,SWT.NONE);
		picLabel.setImage(topImage);
		picLabel.pack();
		
		TabFolder folder = new TabFolder(aboutShell,SWT.TOP);
		TabItem credits = new TabItem(folder,SWT.NONE);
		credits.setText("Credits");
		Text creditText = new Text(folder,SWT.MULTI | SWT.V_SCROLL | SWT.None);
		creditText.insert(readTextFromFile(ClassLoader.getSystemResource(resourceCredits)));
		creditText.setEditable(true);
		
		//creditText.setSize(creditText.computeSize (width, height));
		creditText.setSelection(creditText.getCharCount());
		creditText.pack();
		
		credits.setControl(creditText);
		
		TabItem license =new TabItem(folder,SWT.NONE);
		license.setText("Lizenz");
		Label licenseLabel = new Label(folder,SWT.NONE);
		licenseLabel.setText("nochmal testweise");
		
		//folder.setSize(400,300);
		folder.pack();
		
		Button closeButton = new Button(aboutShell,SWT.PUSH);
		closeButton.setText("okay");
		closeButton.addSelectionListener(new SelectionListener(){
			public void widgetSelected(SelectionEvent e){
				aboutShell.setVisible(false);
				aboutShell.dispose();
			}

			public void widgetDefaultSelected(SelectionEvent arg0) {
				// TODO Auto-generated method stub
				
			}
		});
		
		aboutShell.setLayout(layout);
		aboutShell.setText("Uber Hydra");
		aboutShell.pack();
		//aboutShell.setSize(400,600);
		aboutShell.open();
		
	}
	
	private static String readTextFromFile(URL uri){
		String s = "";
		try{
			BufferedReader input = new BufferedReader( new InputStreamReader(uri.openStream()));
            String line;
            while ((line = input.readLine()) != null){ 
                s = s + line + "\n";
            } 
            input.close();
		}catch(IOException e){
			e.printStackTrace(System.out);
		}
		return s;
	}
}

Das auch soweit, das Text Widget wird aber so gross, wie der String ist. Eine Goressenangabe des Text Widgets wird ignoriert. Wie mache ich das, das das text Widget sagen wir mal 300 Pixel hoch ist, sich in der Groesse nicht veraendert und der text dann gescrollt werden kann ?

Ich komm von gtk#, da ist das alles bisschen einfacher ;) .

CIh hab bestimmt nur was uebersehen - mehrere Augen sehen bekanntlich mehr als zwei ;)

Gruss,
Demo
 
Zurück