Hi Dejan
For Swing applications you would actually need to call Component.isShowing()
instead of Component.isVisible(): If your tab contains a container that in turn
contains components, the visible state of these components is not updated in
Swing.
Because ULC does not currently provide a similar isShowing() API, you would need
to implement such an API yourself. Below you will find a simple sample
implementation of how such an API could look like.
I hope this helps.
Cheers
Rolf
import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.ULCBorderLayoutPane;
import com.ulcjava.base.application.ULCButton;
import com.ulcjava.base.application.ULCComponent;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.ULCTabbedPane;
import com.ulcjava.base.application.ULCTextField;
import com.ulcjava.base.application.event.ActionEvent;
import com.ulcjava.base.application.event.IActionListener;
import com.ulcjava.base.development.DevelopmentRunner;
public class IsVisibleSnippet extends AbstractApplication {
private ULCTextField fTextField1;
private ULCTextField fTextField21;
private ULCTextField fTextField22;
public void start() {
ULCFrame frame = new ULCFrame("IsVisibleSnippet");
ULCTabbedPane tabbedPane1 = new ULCTabbedPane();
ULCTabbedPane tabbedPane2 = new ULCTabbedPane();
fTextField1 = new ULCTextField(40);
fTextField21 = new ULCTextField(40);
fTextField22 = new ULCTextField(40);
tabbedPane1.addTab("1", fTextField1);
tabbedPane1.addTab("2", tabbedPane2);
tabbedPane2.addTab("1", fTextField21);
tabbedPane2.addTab("2", fTextField22);
ULCButton button = new ULCButton("Test");
button.addActionListener(new IActionListener() {
public void actionPerformed(ActionEvent event) {
System.out.println("Helper.isShowing(fTextField1) = "
+ Helper.isShowing(fTextField1));
System.out.println("Helper.isShowing(fTextField21) = "
+ Helper.isShowing(fTextField21));
System.out.println("Helper.isShowing(fTextField22) = "
+ Helper.isShowing(fTextField22));
}
});
ULCBorderLayoutPane pane = new ULCBorderLayoutPane();
pane.add(button, ULCBorderLayoutPane.NORTH);
pane.add(tabbedPane1);
frame.add(pane);
frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
frame.setVisible(true);
}
public static void main(String[] args) {
DevelopmentRunner.setApplicationClass(IsVisibleSnippet.class);
DevelopmentRunner.main(args);
}
public static class Helper {
public static boolean isShowing(ULCComponent component) {
if (!component.isVisible()) {
return false;
}
ULCComponent parent = component.getParent();
if (parent == null) {
return true;
}
if (parent instanceof ULCTabbedPane
&& component != ((ULCTabbedPane)parent).getSelectedComponent())
{
return false;
}
// add more cases here
return isShowing(parent);
}
}
}
**************************************
Rolf Pfenninger
Canoo Engineering AG
Kirschgartenstrasse 7
CH-4051 Basel
Tel +41 61 228 9444
Fax +41 61 228 9449
mailto:[EMAIL PROTECTED]
http://www.canoo.com
ULC - Rich Clients for J2EE
http://www.canoo.com/ulc
**************************************
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of Dejan Pecar
> Sent: Freitag, 15. Dezember 2006 17:18
> To: [email protected]
> Subject: [ULC-developer] visible status of component is not properly
> synchronized to server
>
>
> hi,
>
> i have a problem that the visible status of a component does not get
> synchronized to the server.
>
> see the following two programs one is swing one is ulc. when i press
> the button test in the ulc version
> both labels are always visible. in the swing program it depends on
> which tab is active.
>
> this is a big problem for me because i have validation code which
> validates visible components but since for ulc
> all components are visible even if they are not visible i'm going to
> validate a lot too much components which makes
> my system really slow.
>
> can you fix that as soon as possible ? or give me at least a feasible
> workaround ?
>
> public class SwingTabTest extends JFrame {
> final JLabel tf1 = new JLabel("Feld 1");
> final JLabel tf2 = new JLabel("Feld 2");
> final JButton test = new JButton("test");
>
> public SwingTabTest() {
> JTabbedPane jt = new JTabbedPane();
> jt.setFocusable(false);
> jt.addTab("Tab 1", tf1);
> jt.addTab("Tab 2", tf2);
> getContentPane().setLayout(new BorderLayout());
> test.addActionListener(new ActionListener() {
> public void actionPerformed(ActionEvent e) {
> System.out.println("action");
> System.out.println("tf1 visible: " + tf1.isVisible());
> System.out.println("tf2 visible: " + tf2.isVisible());
> }
> });
> getContentPane().add(test, BorderLayout.NORTH);
> getContentPane().add(jt, BorderLayout.CENTER);
> }
> public static void main(String[] args) {
> SwingTabTest stt = new SwingTabTest();
> stt.setBounds(10,20,300,400);
> stt.setVisible(true);
> }
> }
>
> public class ULCTabTest extends AbstractApplication {
> final ULCLabel lbl1 = new ULCLabel("Tab1");
> final ULCLabel lbl2 = new ULCLabel("Tab2");
> final ULCButton test = new ULCButton("test");
>
> public void start() {
> final ULCFrame frame = new ULCFrame("Test");
> ULCBorderLayoutPane blp = new ULCBorderLayoutPane();
> ULCTabbedPane tp = new ULCTabbedPane();
> tp.setFocusable(false);
> tp.addTab("Tab1", lbl1);
> tp.addTab("Tab2", lbl2);
> frame.setBounds(10, 20, 300, 400);
> frame.setDefaultCloseOperation(ULCFrame.DISPOSE_ON_CLOSE);
> blp.add(tp, ULCBorderLayoutPane.CENTER);
> test.addActionListener(new IActionListener() {
> public void actionPerformed(ActionEvent event) {
> System.out.println("lbl1.visible: " + lbl1.isVisible());
> System.out.println("lbl2.visible: " + lbl2.isVisible());
> }
> });
> blp.add(test, ULCBorderLayoutPane.NORTH);
> frame.getContentPane().add(blp);
> frame.setVisible(true);
> }
> public static void main(String[] args) {
> DevelopmentRunner.setApplicationClass(ULCTabTest.class);
> DevelopmentRunner.main(args);
> }
> }
>
>
> regards
> Dejan
> mailto:[EMAIL PROTECTED]
>
> _______________________________________________
> ULC-developer mailing list
> [email protected]
> http://lists.canoo.com/mailman/listinfo/ulc-developer
_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer