-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
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.
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());
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
Asked: 2010-04-28 04:26:48 +0800
Seen: 292 times
Last updated: Apr 28 '10