I have looked at the login demo, I do not see where my code is wrong. When I use the getWidth(); on the edit fields it returns 800.
Code:
package akclient.interfaces;
import ak.core.logic.user.User;
import ak.core.random.random;
import de.matthiasmann.twl.Button;
import de.matthiasmann.twl.DialogLayout;
import de.matthiasmann.twl.EditField;
import de.matthiasmann.twl.Label;
import de.matthiasmann.twl.Widget;
/**
*
* @author tlf30
*/
public class AKLogin extends Widget{
private static User player = null;
public Button loginB = new Button();
public Button createB = new Button();
private EditField userEF = new EditField();
private EditField passEF = new EditField();
private Label userL = new Label("Username:");
private Label passL = new Label("Password:");
private DialogLayout loginPanel = new DialogLayout();
public AKLogin() {
System.out.println("\t\tCreating interface: login");
setSize(200, 100);
//build gui
//buttons
System.out.println("\t\t\tCreating buttons");
loginB.setText("Login");
loginB.setTheme("loginB");
createB.setText("Create Account");
createB.setTheme("createB");
System.out.println("\t\t\tCreating edit fields");
//edit fields
userEF.setText("Username");
userEF.setTheme("userEF");
userEF.setColumns(20);
userEF.setSize(100, 30);
userEF.setMaxSize(100, 30);
userEF.setMinSize(10, 30);
passEF.setTheme("passEF");
passEF.setPasswordMasking(true);
passEF.setPasswordChar('*');
passEF.setColumns(20);
passEF.setSize(100, 30);
passEF.setMaxSize(300, 30);
passEF.setMinSize(10, 30);
passEF.setText("Password");
System.out.println("\t\t\tCreating labels");
//labels
userL.setLabelFor(userEF);
userL.setTheme("userL");
passL.setLabelFor(passEF);
passL.setTheme("passL");
//layout
System.out.println("\t\t\tCreating panels");
loginPanel.setTheme("loginPL");
//set up interface
System.out.println("\t\t\tGrouping components to panels");
DialogLayout.Group labelsG = loginPanel.createParallelGroup(userL, passL);
DialogLayout.Group EFG = loginPanel.createParallelGroup(userEF, passEF);
DialogLayout.Group buttonG = loginPanel.createSequentialGroup(loginB, createB);
loginPanel.setHorizontalGroup(loginPanel.createParallelGroup()
.addGroup(loginPanel.createSequentialGroup(labelsG, EFG))
.addGroup(buttonG)
);
loginPanel.setVerticalGroup(loginPanel.createSequentialGroup()
.addGroup(loginPanel.createParallelGroup(userL, userEF))
.addGroup(loginPanel.createParallelGroup(passL, passEF))
.addGroup(loginPanel.createParallelGroup(loginB, createB))
);
System.out.println("\t\t\tAdding panels to interface");
this.add(loginPanel);
}
public boolean getLogin() {
random a = new random();
boolean b = a.randomBoolean();
System.out.println("\tTrying login");
if (b == true) {
System.out.println("\t\tLogin: true");
}else {
System.out.println("\t\tLogin: false");
}
return b;
}
public User getUser() {
return player;
}
@Override
protected void layout() {
loginPanel.adjustSize();
loginPanel.setSize(200, 100);
loginPanel.setPosition(
getInnerX() + (getInnerWidth() - loginPanel.getWidth()) / 2,
getInnerY() + (getInnerHeight() - loginPanel.getHeight()) / 2
);
userEF.adjustSize();
passEF.adjustSize();
}
}