0

Swing component in zul?

asked 2010-04-28 04:26:48 +0800

JoH gravatar image JoH
105 2 3

Is there any possibility to use swing component in zul?

I want to display a text file in a textarea (e.g. JTextArea). The problem with Zkoss Textbox is, that it doesn't have append() method like JTextArea has. This is a problem, because the string that will be display, is only the last line of the file.

public void displayOutput(){
			String line2;
			String x = null;
			try{
			final Listbox listbox = (Listbox)this.getFellow("items");
			final Textbox tboutput = (Textbox)this.getFellow("outputviewer");
			
			Listitem lt = listbox.getSelectedItem();
			String path = ((de.qcdb.lmu.domain.Item)lt.getValue()).getFilepath();
			BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("/root/workspace/QCDB/WebContent"+path)));
		
			while((line2 = in.readLine()) != null){
				x = line2;
				tboutput.setValue(x);
			}
			
			}
			catch (IOException e){
				e.printStackTrace();
			}
		}

Source Code

Thanx in advance

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2010-04-28 10:32:27 +0800

xmedeko gravatar image xmedeko
1031 1 16
http://xmedeko.blogspot.c...

Nope it isn't :-) I guess you do not understand much how ZK works. Anyway, you may use <textbox rows="20" />. Also, the code is wrong:

while((line2 = in.readLine()) != null){
	x = line2;
	tboutput.setValue(x);
}

it will always display the last line, does not matter what king of widgets you use.

link publish delete flag offensive edit

answered 2010-04-28 10:32:38 +0800

YamilBracho gravatar image YamilBracho
1722 2

You can use a StringBuilder to collect all the textfile lines and the show them all in a ZK text component. Say


StringBuilder sb = new StringBuilder(2048);
while((line2 = in.readLine()) != null){
   sb.append(line2);
}

tboutput.setValue(sb.toString());



link publish delete flag offensive edit

answered 2010-04-28 11:02:29 +0800

JoH gravatar image JoH
105 2 3

Wow it works, thanks a lot for the tips guys,
The textbox I used, have already 40 rows, but the problem is that zkoss doesn't have a kind of JTextArea, which has the method append.
The only way I knew before is converting every new lines with a specific string and write into a file with single line. Then read again this file and convert it again into newlines. But this reduce the efficiency and consumes more time.
The StringBuilder is really kool. I didn't know there's is this kool class.

Thanx

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-04-28 04:26:48 +0800

Seen: 292 times

Last updated: Apr 28 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More