this.setLayout(new BorderLayout()); TableLayout layout = new TableLayout(5,3);
Container cnt2 = new Container(); cnt2.getStyle().setBgColor(0xd3d3d3); cnt2.getStyle().setBgTransparency(255); cnt2.add(new Label("Activity:"));
Container cnt1 = new Container(layout); cnt1.add(layout.createConstraint().widthPercentage(20), new Label()); cnt1.add(layout.createConstraint().widthPercentage(40), new Label()); cnt1.add(layout.createConstraint().widthPercentage(40), new Label()); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("Last:")); cnt1.add(layout.createConstraint().horizontalSpan(1), new TextField()); cnt1.add(layout.createConstraint().horizontalSpan(1), new TextField());
cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("First:")); cnt1.add(layout.createConstraint().horizontalSpan(1), new TextField()); cnt1.add(layout.createConstraint().horizontalSpan(1).verticalSpan(4), cnt2);
cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("Age:")); cnt1.add(layout.createConstraint().horizontalSpan(1), new TextField());
cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("Height:")); cnt1.add(layout.createConstraint().horizontalSpan(1), new TextField());
cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("Weight:")); cnt1.add(layout.createConstraint().horizontalSpan(1), new TextField()); cnt1.add(layout.createConstraint().horizontalSpan(1), new TextField()); <-----NOTE: this empty field had to be added to align
cnt1.add(layout.createConstraint().horizontalSpan(3), new Label("Some Really Long Text that represents a button panel that should span")); this.add(BorderLayout.CENTER, cnt1);
This is what I got when I ran something similar:
TableLayout layout = new TableLayout(5,3);
Form f = new Form("Table", layout);
f.add(layout.createConstraint().widthPercentage(20), new Label());
f.add(layout.createConstraint().widthPercentage(40), new Label());
f.add(layout.createConstraint().widthPercentage(40), new Label());
f.add(layout.createConstraint().horizontalSpan(1), new Label("Last:"));
f.add(layout.createConstraint().horizontalSpan(1), new TextField());
f.add(layout.createConstraint().horizontalSpan(1), new TextField());
f.add(layout.createConstraint().horizontalSpan(1), new Label("First:"));
f.add(layout.createConstraint().horizontalSpan(1), new TextField());
f.add(layout.createConstraint().horizontalSpan(1).verticalSpan(4),new SpanLabel("Long text\nThat should\nBreak lines\nIn spanning..."));
f.add(layout.createConstraint().horizontalSpan(1), new Label("Age:"));
f.add(layout.createConstraint().horizontalSpan(1), new TextField());
f.add(layout.createConstraint().horizontalSpan(1), new Label("Height:"));
f.add(layout.createConstraint().horizontalSpan(1), new TextField());
f.add(layout.createConstraint().horizontalSpan(1), new Label("Weight:"));
f.add(layout.createConstraint().horizontalSpan(1), new TextField());
f.add(layout.createConstraint().horizontalSpan(1), new TextField());
f.add(layout.createConstraint().horizontalSpan(3), new Label("Some Really Long Text that represents a button panel that should span"));
f.show();
public class FrmMain extends Form { public FrmMain() { initManualComponents(); } protected void initManualComponents() {
this.setLayout(new BorderLayout()); Button btn = new Button("Test"); btn.addActionListener(evt -> onClick()); this.add(BorderLayout.NORTH, btn);
Button btn2 = new Button("Test2"); btn2.addActionListener(evt -> onClick2()); this.add(BorderLayout.SOUTH, btn2);
} protected void onClick() { new MyDlg().show(); } protected void onClick2() { new MyDlg2().show(); } class MyDlg extends Dialog { protected Button btnClose = new Button(FontImage.createMaterial(FontImage.MATERIAL_CLEAR, UIManager.getInstance().getComponentStyle("TitleCommand"))); public MyDlg() { initManualComponents(); } protected void initManualComponents() { this.setLayout(new BorderLayout()); this.getDialogStyle().setBgColor(0xFF0000); this.getStyle().setBgColor(0xFF0000); this.getContentPane().getStyle().setBgColor(0xFF0000); btnClose.addActionListener(evt -> dispose());
TableLayout layout = new TableLayout(10,4);
Container cnt1 = new Container(layout);
cnt1.add(layout.createConstraint().horizontalSpan(4).horizontalAlign(Component.RIGHT), btnClose); cnt1.add(layout.createConstraint().widthPercentage(15), new Label("A")); cnt1.add(layout.createConstraint().widthPercentage(35), new Label("B")); cnt1.add(layout.createConstraint().widthPercentage(35), new Label("C")); cnt1.add(layout.createConstraint().widthPercentage(15), new Label("D"));
cnt1. add(layout.createConstraint().horizontalSpan(2), new Label("Span 2")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("A")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("X"));
cnt1.add(layout.createConstraint().horizontalSpan(3), new Label("Span 3")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("X")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("Span 1")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("Span 1")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("X"));
this.add(BorderLayout.CENTER, cnt1); } } class MyDlg2 extends Dialog { protected Button btnClose = new Button(FontImage.createMaterial(FontImage.MATERIAL_CLEAR, UIManager.getInstance().getComponentStyle("TitleCommand"))); public MyDlg2() { initManualComponents(); } protected void initManualComponents() { this.setLayout(new BorderLayout()); this.getDialogStyle().setBgColor(0xFF0000); this.getStyle().setBgColor(0xFF0000); this.getContentPane().getStyle().setBgColor(0xFF0000); btnClose.addActionListener(evt -> dispose());
TableLayout layout = new TableLayout(10,4);
Container cnt1 = new Container(layout);
cnt1.add(layout.createConstraint().horizontalSpan(4).horizontalAlign(Component.RIGHT), btnClose); cnt1.add(layout.createConstraint().widthPercentage(15), new Label("A")); cnt1.add(layout.createConstraint().widthPercentage(35), new Label("B")); cnt1.add(layout.createConstraint().widthPercentage(35), new Label("C")); cnt1.add(layout.createConstraint().widthPercentage(15), new Label("D"));
cnt1. add(layout.createConstraint().horizontalSpan(2), new Label("Span 2")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("A")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("X"));
cnt1.add(layout.createConstraint().horizontalSpan(3), new Label("Span 3")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("X")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("Span 1")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("Span 1")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("X"));
cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("Span 1")); cnt1.add(layout.createConstraint().horizontalSpan(1), new TextField()); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("X")); this.add(BorderLayout.CENTER, cnt1); } }}
public class FrmMain extends com.codename1.ui.Form { public FrmMain() { this(com.codename1.ui.util.Resources.getGlobalResources()); } public FrmMain(com.codename1.ui.util.Resources resourceObjectInstance) {
initManualComponents(); } protected void initManualComponents() { this.setLayout(new BorderLayout()); Button btn = new Button("Test"); btn.addActionListener(evt -> onClick()); this.add(BorderLayout.NORTH, btn);
Button btn2 = new Button("Test2"); btn2.addActionListener(evt -> onClick2()); this.add(BorderLayout.SOUTH, btn2); } protected void onClick() { new MyDlg().show(); } protected void onClick2() { new MyDlg2().show(); } class MyDlg extends Dialog { protected Button btnClose = new Button(FontImage.createMaterial(FontImage.MATERIAL_CLEAR, UIManager.getInstance().getComponentStyle("TitleCommand"))); public MyDlg() { initManualComponents(); } protected void initManualComponents() { this.setLayout(new BorderLayout());
btnClose.addActionListener(evt -> dispose());
TableLayout layout = new TableLayout(10,4); Container cnt1 = new Container(layout);
cnt1.add(layout.createConstraint().widthPercentage(15), new Label("A")); cnt1.add(layout.createConstraint().widthPercentage(35), new Label("B")); cnt1.add(layout.createConstraint().widthPercentage(35), new Label("C")); cnt1.add(layout.createConstraint().widthPercentage(15), new Label("D"));
cnt1.add(layout.createConstraint().horizontalSpan(4).horizontalAlign(Component.RIGHT), btnClose);
cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("Span 1"));
cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("Textfield"));
cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("X"));
this.add(BorderLayout.CENTER, cnt1); } } class MyDlg2 extends Dialog { protected Button btnClose = new Button(FontImage.createMaterial(FontImage.MATERIAL_CLEAR, UIManager.getInstance().getComponentStyle("TitleCommand"))); public MyDlg2() { initManualComponents(); } protected void initManualComponents() { this.setLayout(new BorderLayout());
btnClose.addActionListener(evt -> dispose());
TableLayout layout = new TableLayout(10,4); Container cnt1 = new Container(layout);
cnt1.add(layout.createConstraint().widthPercentage(15), new Label("A")); cnt1.add(layout.createConstraint().widthPercentage(35), new Label("B")); cnt1.add(layout.createConstraint().widthPercentage(35), new Label("C")); cnt1.add(layout.createConstraint().widthPercentage(15), new Label("D"));
cnt1.add(layout.createConstraint().horizontalSpan(4).horizontalAlign(Component.RIGHT), btnClose);
cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("")); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("Span 1")); cnt1.add(layout.createConstraint().horizontalSpan(1), new TextField()); cnt1.add(layout.createConstraint().horizontalSpan(1), new Label("X")); this.add(BorderLayout.CENTER, cnt1); } }}
d.show(0, 0, Display.getInstance().getDisplayWidth()/2, 0);