Skip to main content

auto scrolling

14 replies [Last post]
Anonymous

hi all,

i have 3 tabpane, and every tab have a container and an textfield for
input string.
the container contain textarea which added every input in textfield, as
chat client.
the problem is when i add the new textarea to the container, cannot auto
scrolling for the last component added.

how auto scrolling working in lwuit ?

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jlester87
Offline
Joined: 2009-06-18

hi,
I successfully implemented autoscrolldown using scrollRectToVisible but the problem is, I can't scroll the container up, when i try to drag the scroll up, it always autoscrolls down.

addComponent(BorderLayout.CENTER, messageForm);

int w = this.getWidth();
int h = this.getHeight();

messageForm.scrollRectToVisible(w, h, w, h, messageForm);

kid24
Offline
Joined: 2008-08-14

Hello,

have you found the solution for this issue?

qazwsx999
Offline
Joined: 2008-09-04

Hi Shai,

I tried exactly that with scrollToComponent, but no luck.

class ContainerExtension extends Container{
public void scrollToComponent(Component c){
super.scrollComponentToVisible(c);
}

}

Then, later on I just do.

myContainer.scrollToComponent(myTextComponent)

Shai Almog

Hi,
you need to make the derived container scrollable on Y
(setScrollableY true) while making the parent form non-scrollable for
this to work.

> Hi Shai,
>
> I tried exactly that with scrollToComponent, but no luck.
>
> class ContainerExtension extends Container{
> public void scrollToComponent(Component c){
> super.scrollComponentToVisible(c);
> }
>
>
> }
>
>
>
> Then, later on I just do.
>
> myContainer.scrollToComponent(myTextComponent)
> [Message sent by forum member 'qazwsx999' (qazwsx999)]
>
> http://forums.java.net/jive/thread.jspa?messageID=300565
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

pakmee
Offline
Joined: 2008-09-01

Hi, if i get it right, then if u have i.e a derived container (scrollableY=TRUE), 2 buttons and the last button is not viewable since container +2 buttons are bigger > form.getheight , u wont be able to scroll to the last button since the parent form is not scrollable.

chen

Hi,
Can you send a code snippet that reproduce this, it's hard for me to
understand what's the problem.

Regards,
Chen

alitmd2008 wrote:
> hi all,
>
> i have 3 tabpane, and every tab have a container and an textfield for
> input string.
> the container contain textarea which added every input in textfield,
> as chat client.
> the problem is when i add the new textarea to the container, cannot
> auto scrolling for the last component added.
>
> how auto scrolling working in lwuit ?
>
>
> Thanks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

alitmd2008

here is my code
========

package pg;

import app.mymidlet;
import com.sun.lwuit.Command;
import com.sun.lwuit.Container;
import com.sun.lwuit.Form;
import com.sun.lwuit.TabbedPane;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.TextField;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.Border;

public class PageChating extends Form implements ActionListener {

mymidlet midku;
Command backtolist = new Command("List user", 1);
Command send = new Command("Close tab", 2);
TabbedPane tp = null;
private ChatContainer con;
ChatContain cc;
private TextArea l;

public PageChating(mymidlet mid) {
midku = mid;
setTitle("Current Chat");
setLayout(new BorderLayout());
setScrollable(false);
tp = new TabbedPane();
CreateTab("user 1");
CreateTab("user 2");
CreateTab("user 3");

addComponent("Center", tp);
tp.setSelectedIndex(0);
addCommand(backtolist);
if(tp.getTabCount() > 1) addCommand(send);
setCommandListener(this);
}

public void CreateTab(String name) {
Container panel = new Container(new BorderLayout());

con = new ChatContainer();
con.setScrollableY(true);
for (int a = 0; a < 10; a++) {
addToContainer(con, "and a long long message and a long long
message and a long long message and a long long message Message => and
this is along long text message from user" + a);
}
panel.addComponent("Center", con);
panel.setScrollable(false);

TextField tf = new TextField(this.getWidth());
tf.setFocus(true);
tf.setMaxSize(10);
panel.addComponent("South", tf);
tf.requestFocus();

tf.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent evt) {
String gettf = ((TextField) evt.getSource()).getText();
addToContainer(con, gettf);
con.requestFocus();
System.out.println("Insert data "+gettf);
}
});

tp.addTab(name, panel);

}

private void addToContainer(Container con, String strcontent) {
l = new TextArea(strcontent, 2,2);

l.setEditable(false);
l.setGrowByContent(true); // cannot auto grow
l.setFocusable(false);
l.setIsScrollVisible(false);
l.getStyle().setBgTransparency(0);

l.getStyle().setBorder(Border.getEmpty());
Container ct = new Container(new BoxLayout(BoxLayout.Y_AXIS));
ct.addComponent(l);

con.addComponent(l);
con.getParent().setScrollableY(true);

System.out.println("component total: " + con.getComponentCount());
}

public void actionPerformed(ActionEvent ae) {
Command cmd = ae.getCommand();
switch (cmd.getId()) {
case 1:
new ListUserOnline(midku).show();
break;
case 2:
if(tp.getTabCount() > 1){
System.out.println("close button clicked");
int activetab = tp.getSelectedIndex();
tp.removeTabAt(activetab);
}
break;
}
}
}

========

chen wrote:
> Hi,
> Can you send a code snippet that reproduce this, it's hard for me to
> understand what's the problem.
>
> Regards,
> Chen
>
> alitmd2008 wrote:
>> hi all,
>>
>> i have 3 tabpane, and every tab have a container and an textfield for
>> input string.
>> the container contain textarea which added every input in textfield,
>> as chat client.
>> the problem is when i add the new textarea to the container, cannot
>> auto scrolling for the last component added.
>>
>> how auto scrolling working in lwuit ?
>>
>>
>> Thanks
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

chen

please send a code I can compile and run.

Regards,
Chen

alitmd2008 wrote:
> here is my code
> ========
>
> package pg;
>
> import app.mymidlet;
> import com.sun.lwuit.Command;
> import com.sun.lwuit.Container;
> import com.sun.lwuit.Form;
> import com.sun.lwuit.TabbedPane;
> import com.sun.lwuit.TextArea;
> import com.sun.lwuit.TextField;
> import com.sun.lwuit.events.ActionEvent;
> import com.sun.lwuit.events.ActionListener;
> import com.sun.lwuit.layouts.BorderLayout;
> import com.sun.lwuit.layouts.BoxLayout;
> import com.sun.lwuit.plaf.Border;
>
> public class PageChating extends Form implements ActionListener {
>
> mymidlet midku;
> Command backtolist = new Command("List user", 1);
> Command send = new Command("Close tab", 2);
> TabbedPane tp = null;
> private ChatContainer con;
> ChatContain cc;
> private TextArea l;
>
> public PageChating(mymidlet mid) {
> midku = mid;
> setTitle("Current Chat");
> setLayout(new BorderLayout());
> setScrollable(false);
> tp = new TabbedPane();
> CreateTab("user 1");
> CreateTab("user 2");
> CreateTab("user 3");
>
> addComponent("Center", tp);
> tp.setSelectedIndex(0);
> addCommand(backtolist);
> if(tp.getTabCount() > 1) addCommand(send);
> setCommandListener(this);
> }
>
> public void CreateTab(String name) {
> Container panel = new Container(new BorderLayout());
>
> con = new ChatContainer();
> con.setScrollableY(true);
> for (int a = 0; a < 10; a++) {
> addToContainer(con, "and a long long message and a long
> long message and a long long message and a long long message Message
> => and this is along long text message from user" + a);
> } panel.addComponent("Center", con);
> panel.setScrollable(false);
>
> TextField tf = new TextField(this.getWidth());
> tf.setFocus(true);
> tf.setMaxSize(10);
> panel.addComponent("South", tf);
> tf.requestFocus();
>
> tf.addActionListener(new ActionListener() {
>
> public void actionPerformed(ActionEvent evt) {
> String gettf = ((TextField) evt.getSource()).getText();
> addToContainer(con, gettf);
> con.requestFocus();
> System.out.println("Insert data "+gettf);
> }
> });
>
> tp.addTab(name, panel);
>
> }
>
> private void addToContainer(Container con, String strcontent) {
> l = new TextArea(strcontent, 2,2);
>
> l.setEditable(false);
> l.setGrowByContent(true); // cannot auto grow
> l.setFocusable(false);
> l.setIsScrollVisible(false);
> l.getStyle().setBgTransparency(0);
>
> l.getStyle().setBorder(Border.getEmpty());
> Container ct = new Container(new BoxLayout(BoxLayout.Y_AXIS));
> ct.addComponent(l);
> con.addComponent(l);
> con.getParent().setScrollableY(true);
>
> System.out.println("component total: " + con.getComponentCount());
> }
>
> public void actionPerformed(ActionEvent ae) {
> Command cmd = ae.getCommand();
> switch (cmd.getId()) {
> case 1:
> new ListUserOnline(midku).show();
> break;
> case 2:
> if(tp.getTabCount() > 1){
> System.out.println("close button clicked");
> int activetab = tp.getSelectedIndex();
> tp.removeTabAt(activetab);
> }
> break;
> }
> }
> }
>
> ========
>
> chen wrote:
>> Hi,
>> Can you send a code snippet that reproduce this, it's hard for me to
>> understand what's the problem.
>>
>> Regards,
>> Chen
>>
>> alitmd2008 wrote:
>>> hi all,
>>>
>>> i have 3 tabpane, and every tab have a container and an textfield
>>> for input string.
>>> the container contain textarea which added every input in textfield,
>>> as chat client.
>>> the problem is when i add the new textarea to the container, cannot
>>> auto scrolling for the last component added.
>>>
>>> how auto scrolling working in lwuit ?
>>>
>>>
>>> Thanks
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

alitmd2008

=====
myMidlet.java
=====
import com.sun.lwuit.Command;
import com.sun.lwuit.Container;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.TabbedPane;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.TextField;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.Border;
import javax.microedition.midlet.MIDlet;

public class myMidlet extends MIDlet {

Command backtolist = new Command("Close Form", 1);
Command send = new Command("Close tab", 2);
TabbedPane tp = null;
private ChatContainer con;
private TextArea l;
Form f;

public void startApp() {
Display.init(this);
f = new Form();
f.setTitle("Current Chat");
f.setLayout(new BorderLayout());
f.setScrollable(false);
tp = new TabbedPane();
CreateTab(f, "user 1");
CreateTab(f, "user 2");

f.addComponent("Center", tp);
tp.setSelectedIndex(0);
f.addCommand(backtolist);
if (tp.getTabCount() > 1) {
f.addCommand(send);
}
f.setCommandListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {
Command cmd = ae.getCommand();
switch (cmd.getId()) {
case 1:
this.notifyDestroyed();
break;
case 2:
if (tp.getTabCount() > 1) {
System.out.println("close button clicked");
int activetab = tp.getSelectedIndex();
tp.removeTabAt(activetab);
if(tp.getTabCount()==1) f.removeCommand(send);
}
break;
}
}

private void notifyDestroyed() {

}
});
f.show();
}

public void pauseApp() {
}

public void CreateTab(Form f, String name) {
Container panel = new Container(new BorderLayout());

con = new ChatContainer();
con.setScrollableY(true);
for (int a = 0; a < 3; a++) {
addToContainer(con, "and a long long message and a long long
message and a long long message and a long long message Message => and
this is along long text message from user" + a);
}
panel.addComponent("Center", con);
panel.setScrollable(false);

TextField tf = new TextField();
tf.setFocus(true);
tf.setMaxSize(10);
panel.addComponent("South", tf);
tf.requestFocus();

tf.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent evt) {
String gettf = ((TextField) evt.getSource()).getText();
addToContainer(con, gettf);
con.requestFocus();
System.out.println("Insert data " + gettf);
}
});

tp.addTab(name, panel);

}

private void addToContainer(Container con, String strcontent) {
l = new TextArea(strcontent, 2, 2);

l.setEditable(false);
l.setGrowByContent(true); // cannot auto grow

l.setFocusable(false);
l.setIsScrollVisible(false);
l.getStyle().setBgTransparency(0);

l.getStyle().setBorder(Border.getEmpty());
Container ct = new Container(new BoxLayout(BoxLayout.Y_AXIS));
ct.addComponent(l);

con.addComponent(ct);

System.out.println("component total: " + con.getComponentCount());
}

public void destroyApp(boolean unconditional) {
}
}

========
ChatContainer.java
========
import com.sun.lwuit.Component;
import com.sun.lwuit.Container;
import com.sun.lwuit.layouts.BoxLayout;

public class ChatContainer extends Container{

public ChatContainer(){
setLayout(new BoxLayout(BoxLayout.Y_AXIS));
setScrollableY(true);
setScrollableX(true);
//setSmoothScrolling(true);
setFocusable(true);
scrollComponentToVisible(this);
}
public void addMsg(Component cn){
addComponent(cn);
System.out.println("Jumlah component: " + getComponentCount());
}
}

===========

chen wrote:
> please send a code I can compile and run.
>
> Regards,
> Chen
>
> alitmd2008 wrote:
>> here is my code
>> ========
>>
>> package pg;
>>
>> import app.mymidlet;
>> import com.sun.lwuit.Command;
>> import com.sun.lwuit.Container;
>> import com.sun.lwuit.Form;
>> import com.sun.lwuit.TabbedPane;
>> import com.sun.lwuit.TextArea;
>> import com.sun.lwuit.TextField;
>> import com.sun.lwuit.events.ActionEvent;
>> import com.sun.lwuit.events.ActionListener;
>> import com.sun.lwuit.layouts.BorderLayout;
>> import com.sun.lwuit.layouts.BoxLayout;
>> import com.sun.lwuit.plaf.Border;
>>
>> public class PageChating extends Form implements ActionListener {
>>
>> mymidlet midku;
>> Command backtolist = new Command("List user", 1);
>> Command send = new Command("Close tab", 2);
>> TabbedPane tp = null;
>> private ChatContainer con;
>> ChatContain cc;
>> private TextArea l;
>>
>> public PageChating(mymidlet mid) {
>> midku = mid;
>> setTitle("Current Chat");
>> setLayout(new BorderLayout());
>> setScrollable(false);
>> tp = new TabbedPane();
>> CreateTab("user 1");
>> CreateTab("user 2");
>> CreateTab("user 3");
>>
>> addComponent("Center", tp);
>> tp.setSelectedIndex(0);
>> addCommand(backtolist);
>> if(tp.getTabCount() > 1) addCommand(send);
>> setCommandListener(this);
>> }
>>
>> public void CreateTab(String name) {
>> Container panel = new Container(new BorderLayout());
>>
>> con = new ChatContainer();
>> con.setScrollableY(true);
>> for (int a = 0; a < 10; a++) {
>> addToContainer(con, "and a long long message and a long
>> long message and a long long message and a long long message Message
>> => and this is along long text message from user" + a);
>> } panel.addComponent("Center", con);
>> panel.setScrollable(false);
>>
>> TextField tf = new TextField(this.getWidth());
>> tf.setFocus(true);
>> tf.setMaxSize(10);
>> panel.addComponent("South", tf);
>> tf.requestFocus();
>>
>> tf.addActionListener(new ActionListener() {
>>
>> public void actionPerformed(ActionEvent evt) {
>> String gettf = ((TextField) evt.getSource()).getText();
>> addToContainer(con, gettf);
>> con.requestFocus();
>> System.out.println("Insert data "+gettf);
>> }
>> });
>>
>> tp.addTab(name, panel);
>>
>> }
>>
>> private void addToContainer(Container con, String strcontent) {
>> l = new TextArea(strcontent, 2,2);
>>
>> l.setEditable(false);
>> l.setGrowByContent(true); // cannot auto grow
>> l.setFocusable(false);
>> l.setIsScrollVisible(false);
>> l.getStyle().setBgTransparency(0);
>>
>> l.getStyle().setBorder(Border.getEmpty());
>> Container ct = new Container(new BoxLayout(BoxLayout.Y_AXIS));
>> ct.addComponent(l);
>> con.addComponent(l);
>> con.getParent().setScrollableY(true);
>>
>> System.out.println("component total: " +
>> con.getComponentCount());
>> }
>> public void actionPerformed(ActionEvent ae) {
>> Command cmd = ae.getCommand();
>> switch (cmd.getId()) {
>> case 1:
>> new ListUserOnline(midku).show();
>> break;
>> case 2:
>> if(tp.getTabCount() > 1){
>> System.out.println("close button clicked");
>> int activetab = tp.getSelectedIndex();
>> tp.removeTabAt(activetab);
>> }
>> break;
>> }
>> }
>> }
>>
>> ========
>>
>> chen wrote:
>>> Hi,
>>> Can you send a code snippet that reproduce this, it's hard for me to
>>> understand what's the problem.
>>>
>>> Regards,
>>> Chen
>>>
>>> alitmd2008 wrote:
>>>> hi all,
>>>>
>>>> i have 3 tabpane, and every tab have a container and an textfield
>>>> for input string.
>>>> the container contain textarea which added every input in
>>>> textfield, as chat client.
>>>> the problem is when i add the new textarea to the container, cannot
>>>> auto scrolling for the last component added.
>>>>
>>>> how auto scrolling working in lwuit ?
>>>>
>>>>
>>>> Thanks
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>>>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>>>
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

chen

Hi,
The Scrolling is not happening for you because you add widgets and you
don't allow them to grab focus.

remove this line:
l.setFocusable(false);
from the addToContainer method

Regards,
Chen

alitmd2008 wrote:
> =====
> myMidlet.java
> =====
> import com.sun.lwuit.Command;
> import com.sun.lwuit.Container;
> import com.sun.lwuit.Display;
> import com.sun.lwuit.Form;
> import com.sun.lwuit.TabbedPane;
> import com.sun.lwuit.TextArea;
> import com.sun.lwuit.TextField;
> import com.sun.lwuit.events.ActionEvent;
> import com.sun.lwuit.events.ActionListener;
> import com.sun.lwuit.layouts.BorderLayout;
> import com.sun.lwuit.layouts.BoxLayout;
> import com.sun.lwuit.plaf.Border;
> import javax.microedition.midlet.MIDlet;
>
>
> public class myMidlet extends MIDlet {
>
> Command backtolist = new Command("Close Form", 1);
> Command send = new Command("Close tab", 2);
> TabbedPane tp = null;
> private ChatContainer con;
> private TextArea l;
> Form f;
>
> public void startApp() {
> Display.init(this);
> f = new Form();
> f.setTitle("Current Chat");
> f.setLayout(new BorderLayout());
> f.setScrollable(false);
> tp = new TabbedPane();
> CreateTab(f, "user 1");
> CreateTab(f, "user 2");
>
> f.addComponent("Center", tp);
> tp.setSelectedIndex(0);
> f.addCommand(backtolist);
> if (tp.getTabCount() > 1) {
> f.addCommand(send);
> }
> f.setCommandListener(new ActionListener() {
>
> public void actionPerformed(ActionEvent ae) {
> Command cmd = ae.getCommand();
> switch (cmd.getId()) {
> case 1:
> this.notifyDestroyed();
> break;
> case 2:
> if (tp.getTabCount() > 1) {
> System.out.println("close button clicked");
> int activetab = tp.getSelectedIndex();
> tp.removeTabAt(activetab);
> if(tp.getTabCount()==1) f.removeCommand(send);
> }
> break;
> }
> }
>
> private void notifyDestroyed() {
> }
> });
> f.show();
> }
>
> public void pauseApp() {
> }
>
> public void CreateTab(Form f, String name) {
> Container panel = new Container(new BorderLayout());
>
> con = new ChatContainer();
> con.setScrollableY(true);
> for (int a = 0; a < 3; a++) {
> addToContainer(con, "and a long long message and a long
> long message and a long long message and a long long message Message
> => and this is along long text message from user" + a);
> }
> panel.addComponent("Center", con);
> panel.setScrollable(false);
>
> TextField tf = new TextField();
> tf.setFocus(true);
> tf.setMaxSize(10);
> panel.addComponent("South", tf);
> tf.requestFocus();
>
> tf.addActionListener(new ActionListener() {
>
> public void actionPerformed(ActionEvent evt) {
> String gettf = ((TextField) evt.getSource()).getText();
> addToContainer(con, gettf);
> con.requestFocus();
> System.out.println("Insert data " + gettf);
> }
> });
>
> tp.addTab(name, panel);
>
> }
>
> private void addToContainer(Container con, String strcontent) {
> l = new TextArea(strcontent, 2, 2);
>
> l.setEditable(false);
> l.setGrowByContent(true); // cannot auto grow
>
> l.setFocusable(false);
> l.setIsScrollVisible(false);
> l.getStyle().setBgTransparency(0);
>
> l.getStyle().setBorder(Border.getEmpty());
> Container ct = new Container(new BoxLayout(BoxLayout.Y_AXIS));
> ct.addComponent(l);
>
> con.addComponent(ct);
>
> System.out.println("component total: " + con.getComponentCount());
> }
>
> public void destroyApp(boolean unconditional) {
> }
> }
>
> ========
> ChatContainer.java
> ========
> import com.sun.lwuit.Component;
> import com.sun.lwuit.Container;
> import com.sun.lwuit.layouts.BoxLayout;
>
> public class ChatContainer extends Container{
>
> public ChatContainer(){
> setLayout(new BoxLayout(BoxLayout.Y_AXIS));
> setScrollableY(true);
> setScrollableX(true);
> //setSmoothScrolling(true);
> setFocusable(true);
> scrollComponentToVisible(this);
> }
> public void addMsg(Component cn){
> addComponent(cn);
> System.out.println("Jumlah component: " + getComponentCount());
> }
> }
>
> ===========
>
>
> chen wrote:
>> please send a code I can compile and run.
>>
>> Regards,
>> Chen
>>
>> alitmd2008 wrote:
>>> here is my code
>>> ========
>>>
>>> package pg;
>>>
>>> import app.mymidlet;
>>> import com.sun.lwuit.Command;
>>> import com.sun.lwuit.Container;
>>> import com.sun.lwuit.Form;
>>> import com.sun.lwuit.TabbedPane;
>>> import com.sun.lwuit.TextArea;
>>> import com.sun.lwuit.TextField;
>>> import com.sun.lwuit.events.ActionEvent;
>>> import com.sun.lwuit.events.ActionListener;
>>> import com.sun.lwuit.layouts.BorderLayout;
>>> import com.sun.lwuit.layouts.BoxLayout;
>>> import com.sun.lwuit.plaf.Border;
>>>
>>> public class PageChating extends Form implements ActionListener {
>>>
>>> mymidlet midku;
>>> Command backtolist = new Command("List user", 1);
>>> Command send = new Command("Close tab", 2);
>>> TabbedPane tp = null;
>>> private ChatContainer con;
>>> ChatContain cc;
>>> private TextArea l;
>>>
>>> public PageChating(mymidlet mid) {
>>> midku = mid;
>>> setTitle("Current Chat");
>>> setLayout(new BorderLayout());
>>> setScrollable(false);
>>> tp = new TabbedPane();
>>> CreateTab("user 1");
>>> CreateTab("user 2");
>>> CreateTab("user 3");
>>>
>>> addComponent("Center", tp);
>>> tp.setSelectedIndex(0);
>>> addCommand(backtolist);
>>> if(tp.getTabCount() > 1) addCommand(send);
>>> setCommandListener(this);
>>> }
>>>
>>> public void CreateTab(String name) {
>>> Container panel = new Container(new BorderLayout());
>>>
>>> con = new ChatContainer();
>>> con.setScrollableY(true);
>>> for (int a = 0; a < 10; a++) {
>>> addToContainer(con, "and a long long message and a long
>>> long message and a long long message and a long long message
>>> Message => and this is along long text message from user" + a);
>>> } panel.addComponent("Center", con);
>>> panel.setScrollable(false);
>>>
>>> TextField tf = new TextField(this.getWidth());
>>> tf.setFocus(true);
>>> tf.setMaxSize(10);
>>> panel.addComponent("South", tf);
>>> tf.requestFocus();
>>>
>>> tf.addActionListener(new ActionListener() {
>>>
>>> public void actionPerformed(ActionEvent evt) {
>>> String gettf = ((TextField) evt.getSource()).getText();
>>> addToContainer(con, gettf);
>>> con.requestFocus();
>>> System.out.println("Insert data "+gettf);
>>> }
>>> });
>>>
>>> tp.addTab(name, panel);
>>>
>>> }
>>>
>>> private void addToContainer(Container con, String strcontent) {
>>> l = new TextArea(strcontent, 2,2);
>>>
>>> l.setEditable(false);
>>> l.setGrowByContent(true); // cannot auto grow
>>> l.setFocusable(false);
>>> l.setIsScrollVisible(false);
>>> l.getStyle().setBgTransparency(0);
>>>
>>> l.getStyle().setBorder(Border.getEmpty());
>>> Container ct = new Container(new BoxLayout(BoxLayout.Y_AXIS));
>>> ct.addComponent(l);
>>> con.addComponent(l);
>>> con.getParent().setScrollableY(true);
>>>
>>> System.out.println("component total: " +
>>> con.getComponentCount());
>>> }
>>> public void actionPerformed(ActionEvent ae) {
>>> Command cmd = ae.getCommand();
>>> switch (cmd.getId()) {
>>> case 1:
>>> new ListUserOnline(midku).show();
>>> break;
>>> case 2:
>>> if(tp.getTabCount() > 1){
>>> System.out.println("close button clicked");
>>> int activetab = tp.getSelectedIndex();
>>> tp.removeTabAt(activetab);
>>> }
>>> break;
>>> }
>>> }
>>> }
>>>
>>> ========
>>>
>>> chen wrote:
>>>> Hi,
>>>> Can you send a code snippet that reproduce this, it's hard for me
>>>> to understand what's the problem.
>>>>
>>>> Regards,
>>>> Chen
>>>>
>>>> alitmd2008 wrote:
>>>>> hi all,
>>>>>
>>>>> i have 3 tabpane, and every tab have a container and an textfield
>>>>> for input string.
>>>>> the container contain textarea which added every input in
>>>>> textfield, as chat client.
>>>>> the problem is when i add the new textarea to the container,
>>>>> cannot auto scrolling for the last component added.
>>>>>
>>>>> how auto scrolling working in lwuit ?
>>>>>
>>>>>
>>>>> Thanks
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>>>>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>>>>
>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>>>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>>>
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
>> For additional commands, e-mail: users-help@lwuit.dev.java.net
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

alitmd2008

Hi chen,

thanks for you reply, but what i means is when i do addToContainer(con,
gettf) on tf ActionListerner, i want the container scroll up (auto
scroll up) for showing the last gettf or can i set auto focus to the
last widget i added (TextArea) ?

chen wrote:
> Hi,
> The Scrolling is not happening for you because you add widgets and you
> don't allow them to grab focus.
>
> remove this line:
> l.setFocusable(false);
> from the addToContainer method
>
> Regards,
> Chen
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

chen

Hi,
See Component.scrollRectToVisible(...) method.

Regards,
Chen

alitmd2008 wrote:
> Hi chen,
>
> thanks for you reply, but what i means is when i do
> addToContainer(con, gettf) on tf ActionListerner, i want the container
> scroll up (auto scroll up) for showing the last gettf or can i set
> auto focus to the last widget i added (TextArea) ?
>
> chen wrote:
>> Hi,
>> The Scrolling is not happening for you because you add widgets and
>> you don't allow them to grab focus.
>>
>> remove this line:
>> l.setFocusable(false);
>> from the addToContainer method
>>
>> Regards,
>> Chen
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

kid24
Offline
Joined: 2008-08-14

but the method scrollRectToVisible(...) can't be invoked on the component instance, cause it is protected.

I have the same problem as alitmd2008. I need to auto-scroll textarea to the last row without giving the focus to it. Is it possible?

Shai Almog

Since container scrolling in LWUIT (and to some degree in mobile
devices) is based on focus and you disabled focus scrolling just
won't work for you.
However, you can implement scrolling on your own (like we did
internally in List, TextArea etc.) to show LWUIT how you want
scrolling to behave. To do this you must derive and use
scrollRectToVisible (which is visible to subclasses).

> but the method scrollRectToVisible(...) can't be invoked on the
> component instance, cause it is protected.
>
> I have the same problem as alitmd2008. I need to auto-scroll
> textarea to the last row without giving the focus to it. Is it
> possible?
> [Message sent by forum member 'kid24' (kid24)]
>
> http://forums.java.net/jive/thread.jspa?messageID=300408
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

Shai Almog
http://lwuit.blogspot.com/

[att1.html]