dipgirl
dipgirl

Reputation: 690

How to move the label to center

I want to do the app when I press the tab button the result(website) will show at the center. Now the result is like this the result show at bellow:

enter image description here

But I want my result like this: For example when I press home will show google website then when I press the video tab it will change to youtube website. enter image description here

Here is my coding:

public void start() 
{
    if(current != null)
    {
        current.show();
        return;
    }

    Toolbar.setGlobalToolbar(true);

    Form page = new Form("Apps", new BorderLayout());
    Style s = UIManager.getInstance().getComponentStyle("TitleCommand");
    FontImage icon = FontImage.createMaterial(FontImage.MATERIAL_BORDER_ALL, s);
    page.getToolbar().addCommandToRightBar("", icon, (e) -> Log.p("Right"));


    BrowserComponent browser = new BrowserComponent();
    browser.setURL("https://google.com");
    page.add(BorderLayout.CENTER, browser);

    Tabs t = new Tabs();
    Style st = UIManager.getInstance().getComponentStyle("Tab");
    FontImage home = FontImage.createMaterial(FontImage.MATERIAL_HOME, st);
    FontImage dash = FontImage.createMaterial(FontImage.MATERIAL_MUSIC_VIDEO, st);
    FontImage cal = FontImage.createMaterial(FontImage.MATERIAL_SEARCH, st);

    t.addTab("Home", home, new Label("website 1"));
    t.addTab("Video", dash, new Label("website 2"));
    t.addTab("Search", cal, new Label("website 3"));

    page.add(BorderLayout.SOUTH, t);
    page.show();
}

Can you help me? Thank you

Upvotes: 1

Views: 40

Answers (1)

Shai Almog
Shai Almog

Reputation: 52760

You are using tabs without adding anything into them. Tabs replace the entire content of the screen which isn't the right thing for what you are trying to accomplish. You must have confused my comment in a different form where I referred to the bottom mode of the tabs container.

Instead of using tabs just use toggle buttons:

BrowserComponent browser = new BrowserComponent();
browser.setURL("https://google.com");
page.add(BorderLayout.CENTER, browser);

FontImage home = FontImage.createMaterial(FontImage.MATERIAL_HOME, st);
FontImage dash = FontImage.createMaterial(FontImage.MATERIAL_MUSIC_VIDEO, st);
FontImage cal = FontImage.createMaterial(FontImage.MATERIAL_SEARCH, st);

ButtonGroup bg = new ButtonGroup();
RadioButton home = RadioButton.createToggle("Home", bg);
home.setMaterialIcon(FontImage.MATERIAL_HOME);
RadioButton dash = RadioButton.createToggle("Video", bg);
dash.setMaterialIcon(FontImage.MATERIAL_MUSIC_VIDEO);
RadioButton cal = RadioButton.createToggle("Search", bg);
cal.setMaterialIcon(FontImage.MATERIAL_SEARCH);

page.add(BorderLayout.SOUTH, GridLayout.encloseIn(3, home, dash, cal));

dash.addActionListener(e -> browser.setURL("https://youtube.com/"));

Upvotes: 1

Related Questions