Posted August 14, 201411 yr Hi! I have an GUI made, and I want to add a text box to it but I don't know how, can someone help me? Woking at my first mod, Blocks & Items Revolution : https://github.com/megabitus98/Blocks-Items-Revolution
August 14, 201411 yr private GuiTextField text; public void initGui() { this.text = new GuiTextField(this.fontRendererObj, this.width / 2 - 68, this.height/2-46, 137, 20); text.setMaxStringLength(23); text.setText("sample text"); this.text.setFocused(true); } protected void keyTyped(char par1, int par2) { super.keyTyped(par1, par2); this.text.textboxKeyTyped(par1, par2); } public void updateScreen() { super.updateScreen(); this.text.updateCursorCounter(); } public void drawScreen(int par1, int par2, float par3) { this.drawDefaultBackground(); this.text.drawTextBox(); super.drawScreen(par1, par2, par3); } protected void mouseClicked(int x, int y, int btn) { super.mouseClicked(x, y, btn); this.text.mouseClicked(x, y, btn); }
August 14, 201411 yr Author THX so much for the fast reply but, when I press 'e', I exit the GUI while I was typing, how can this be fixed? Woking at my first mod, Blocks & Items Revolution : https://github.com/megabitus98/Blocks-Items-Revolution
August 14, 201411 yr It's posible to make text box able to type numbers only, not letters? set text.setFocused(false) before exit exit from where?
August 14, 201411 yr I mean closing gui. For number-only textfield... um... you can look at my spinner code https://gist.github.com/MultiMote/479db07ec89ce675c5a6
August 14, 201411 yr I mean closing gui. stop, stop. How it how it helps, if GUI closes while typing 'e' letter? when I press 'e', I exit the GUI while I was typing
August 14, 201411 yr Author I mean closing gui. stop, stop. How it how it helps, if GUI closes while typing 'e' letter? when I press 'e', I exit the GUI while I was typing Is right we want to stop closing the Gui when we press E. Woking at my first mod, Blocks & Items Revolution : https://github.com/megabitus98/Blocks-Items-Revolution
August 14, 201411 yr Maybe something like this? protected void keyTyped(char par1, int par2) { this.text.textboxKeyTyped(par1, par2); if(!( par2== Keyboard.KEY_E && this.text.isFocused())) super.keyTyped(par1, par2); }
August 14, 201411 yr Author Maybe something like this? protected void keyTyped(char par1, int par2) { this.text.textboxKeyTyped(par1, par2); if(!( par2== Keyboard.KEY_E && this.text.isFocused())) super.keyTyped(par1, par2); } THX Works perfectly!!!! Woking at my first mod, Blocks & Items Revolution : https://github.com/megabitus98/Blocks-Items-Revolution
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.