PDA

View Full Version : How to refresh a visible window after using addText()



MickeyMiner
8 Feb 2012, 5:36 AM
Hi,

I have a very simple Logging class, which accepts messages and shows the 100 newest ones in a static window. From any class I call then Logger.log("This is my message to log")
The added messages are not shown immediately, but only after resizing this Logger window.
How do I tell the window to repaint, or to render the newly added message and scroll down to it immediately?

Thank you for your support,

MickeyMiner

PS: Things like win.repaint() or win.render() did not work for me...


import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout;

public class Logger {

static Window win;

Logger() {
win = new Window();
win.setSize(400, 100);
win.setHeading("Logger");
win.setLayout(new VBoxLayout());
win.setScrollMode(Scroll.AUTO);
}
public static void log(String message) {
if (win.getItemCount() >= 100)
win.remove(win.getWidget(0));
win.addText(message);
win.scrollIntoView(win.getItem(win.getItemCount()-1));
}
public void show() {
win.setVisible(true);
}
}

catalin.ciobanu
8 Feb 2012, 8:01 AM
have you tried to call layout() on your window ?

MickeyMiner
10 Feb 2012, 5:28 AM
Thank you! Worked.

However the win.scrollIntoView(win.getItem(win.getItemCount()-1)); will not scroll onto last element... And the Window does not have any scroll bar even thought win.setScrollMode(Scroll.AUTO); was called.

Can you pleas help me on this one?

mm

catalin.ciobanu
10 Feb 2012, 5:31 AM
try to add it using css if it doesn't work using the gxt methods


window.setStyleAttribute("overflow","scroll");

it might just work ... but first make sure you tried this by using the object's methods .. setScroll(Scroll.AUTOY)


this code is not tested, it's meant to guide you ...

MickeyMiner
10 Feb 2012, 6:45 AM
Very good! Everything works now like it should...
Thank you for your quick and competent response!
m.

My final Logger class looks like this:


package de.mike.client;

import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.core.XDOM;
import com.extjs.gxt.ui.client.util.Size;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Text;
import com.extjs.gxt.ui.client.widget.Window;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;

public class Logger {

static Window win;
static LayoutContainer lc;

Logger() {
win = new Window();
win.setSize(800, 300);
win.setPlain(true);
win.setModal(false);
win.setHeading("Logger");
win.setAutoHide(false);
win.setLayout(new FitLayout());
lc = new LayoutContainer();
lc.setScrollMode(Scroll.AUTO);
win.add(lc);
}

public static void log(String message) {
// Maximum of 100 Messages in the buffer
if (lc.getItemCount() > 100)
lc.remove(lc.getWidget(0));

// Add new Message and scroll to it
Text text = new Text("<pre style='font-size:90%'>" + message + "</pre>");
lc.add(text);
lc.layout();
lc.scrollIntoView(text);
}

public void show() {
win.show();
// Move the window to lower right corner
Size s = XDOM.getViewportSize();
int left = s.width - win.getWidth() - 10;
int top = s.height - win.getHeight() - 10;
win.setPosition(left, top);
}

}