Slick Forums

Discuss the Slick 2D Library
It is currently Mon May 20, 2013 1:03 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: EditField not resizing
PostPosted: Mon Nov 21, 2011 9:39 pm 
Offline

Joined: Mon Oct 31, 2011 4:36 pm
Posts: 18
I have several EditFields, and they ignore me when I ues a setSize(100, 30); method, the hight works but not the width. Also I have enabled password masking and set the char but when I type nothing shows up, even though I can use the getText(); method and I get the text I typed.


Top
 Profile  
 
PostPosted: Mon Nov 21, 2011 10:33 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
Well - I also have several EditFields and they respect the size I give them. And text entry also works.

I suggest you provide a bit more info (eg paste the code in question). And check the TWL demos (like the LoginDemo).

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Tue Nov 22, 2011 12:11 am 
Offline

Joined: Mon Oct 31, 2011 4:36 pm
Posts: 18
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();
    }
   
   
}   




Top
 Profile  
 
PostPosted: Tue Nov 22, 2011 7:07 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
Ok a few things are wrong:
a) you set lots of parameters which are overwritten by the theme like "columns", "minWidth/Height", "maxWidth/Height", "passwordChar".
b) you call adjustSize() on not direct children: you added the edit fields to a DialogLayout (loginPanel) - so only that DialogLayout is responsible to do position & size of it's children
c) you call adjustSize() on the loginPanel but directly after that you call setSize() on it ....
d) you call setSize() in your constructor - which is always wrong

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Tue Nov 22, 2011 7:19 pm 
Offline

Joined: Mon Oct 31, 2011 4:36 pm
Posts: 18
Well then how do I make the dialoge layout make the lenght at the correct size, and if thats the case how come setSize works on the hight.


Top
 Profile  
 
PostPosted: Tue Nov 22, 2011 8:09 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1171
In the theme you need to set "maxWidth" to 32767 (or any number > minWidth if you want to limit the max width), and set "columns" to 0.

Basically a max width/height of 0 means no expansion as written in the javadoc.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Mon Nov 28, 2011 3:52 pm 
Offline

Joined: Mon Oct 31, 2011 4:36 pm
Posts: 18
Ok the changes you gave me made no diffrence, I would also like to know how to get my input with the widgets having there own classes.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group