Custom TABS with SpanButton button display width broken

50 views
Skip to first unread message

shop.servic...@gmail.com

unread,
Aug 27, 2019, 9:56:59 AM8/27/19
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA Netbeans 11
Desktop OS Windows 10 Pro
Simulator Latest
Device PC, IOS

Recent build (last 10 days approx) has produced an unusual horizontal with TABS component display.
See attached pic.

Purpose of this overriding TABS class is to provide multi line text support

It appears that the SpanButton class is the problem as I see similar behavior placing this component in a table container.

Here is a simple re-producible case

            Form hi = new Form("Custom Tabs", new BorderLayout());
            Tabs tb = new Tabs(Component.TOP) {
                @Override
                protected Component createTab(String title, Image icon) {
                    SpanButton custom = new SpanButton(title);
                    custom.setName("SpanButton");
                    custom.setIcon(icon);
                    custom.setUIID("Container");
                    custom.setTextUIID("mpiTabMetalUnSelected");
                    custom.setIconPosition(BorderLayout.NORTH);
                    return custom;
                }

                @Override
                public String getTabTitle(Component tab) {
                    return ((SpanButton) tab).getText();
                }

                @Override
                public String getTabTitle(int index) {
                    String TabTitle = "";
                    try {
                        for (int a = 0; a < getComponentCount(); a++) {
                            Container cnt = (Container) getComponentAt(a);
                            for (int b = 0; b < cnt.getComponentCount(); b++) {
                                if (cnt.getComponentAt(b).getName() != null && cnt.getComponentAt(b).getName().compareToIgnoreCase("SpanButton") == 0 && index == b) {
                                    return getTabTitle(cnt.getComponentAt(b));
                                }
                            }
                        }
                    } catch (Exception g) {
                        g.printStackTrace();
                    }
                    return TabTitle;
                }

                @Override
                public void setTabTitle(String title, Image icon, int index) {
                    try {
                        for (int a = 0; a < getComponentCount(); a++) {
                            Container cnt = (Container) getComponentAt(a);
                            for (int b = 0; b < cnt.getComponentCount(); b++) {
                                if (cnt.getComponentAt(b).getName() != null && cnt.getComponentAt(b).getName().compareToIgnoreCase("SpanButton") == 0 && index == b) {
                                    SpanButton custom = (SpanButton) cnt.getComponentAt(b);
                                    custom.setText(title);
                                    return;
                                }
                            }
                        }
                    } catch (Exception g) {
                        g.printStackTrace();
                    }
                }

                @Override
                protected void setTabSelectedIcon(Component tab, Image icon) {
                    ((SpanButton) tab).setPressedIcon(icon);
                }

                protected void selectTab(Component tab) {
                    for (int a = 0; a < this.getComponentCount(); a++) {
                        Container cmp1 = (Container) this.getComponentAt(a);
                        int selIndex = this.getSelectedIndex();
                        for (int b = 0; b < cmp1.getComponentCount(); b++) {
                            if (cmp1.getComponentAt(b).getName() != null && cmp1.getComponentAt(b).getName().startsWith("SpanButton") == true) {
                                if (selIndex == b) {
                                    ((SpanButton) tab).setTextUIID("mpiTabMetalSelected");
                                } else {
                                    ((SpanButton) cmp1.getComponentAt(b)).setTextUIID("mpiTabMetalUnSelected");
                                }
                            }
                        }
                    }
                }

                @Override
                protected void bindTabActionListener(Component tab, ActionListener l) {
                    ((SpanButton) tab).addActionListener(l);
                }
            };
            tb.addSelectionListener(new SelectionListener() {
                @Override
                public void selectionChanged(int oldSelected, int newSelected) {
                }
            });

            tb.setTabUIID(null);
            Button btn = new Button("Any Button Action");
            tb.addTab("Tab 1", btn);
            tb.addTab("Really long\ntext in tab", new Label("T2"));
            tb.addTab("Tab 3", new Label("T3"));
            tb.addTab("Tab 4", new Label("T4"));
            hi.add(BorderLayout.CENTER, tb);
            hi.show();

Regards
TabsSpanButtonWidthProblem-08-27-2019.PNG

Shai Almog

unread,
Aug 28, 2019, 1:08:02 AM8/28/19
to CodenameOne Discussions
Hi,
I think this was triggered by this commit:

Steve can we make that logic conditional?

Steve Hannah

unread,
Aug 29, 2019, 12:15:54 PM8/29/19
to codenameone...@googlegroups.com
I have just made some changes to SpanLabel to fix a regression but don't know if it is related to this issue.  I haves added your provided test case as a Sample, named TabsWityhSpanLabelsTest.  You can run the sample against the latest sources in the Samples Runner.  This is what I see when I run the sample.  Is this correct, or is there something wrong with this layout?

image.png

--
You received this message because you are subscribed to the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/0c600f02-f7a6-4884-ba5e-68c7600ffdf7%40googlegroups.com.


--
Steve Hannah
Software Developer
Codename One

shop.servic...@gmail.com

unread,
Sep 4, 2019, 7:37:03 PM9/4/19
to CodenameOne Discussions
Thanks, this looks correct.


On Thursday, August 29, 2019 at 12:15:54 PM UTC-4, Steve Hannah wrote:
I have just made some changes to SpanLabel to fix a regression but don't know if it is related to this issue.  I haves added your provided test case as a Sample, named TabsWityhSpanLabelsTest.  You can run the sample against the latest sources in the Samples Runner.  This is what I see when I run the sample.  Is this correct, or is there something wrong with this layout?

image.png

To unsubscribe from this group and stop receiving emails from it, send an email to codenameone-discussions+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages