Jump to content

Make EditBox active and focused when screen opened [1.19.2] [SOLVED]


RInventor7

Recommended Posts

Hi! I have screen that has some edit boxes on it. When player opens the screen I would like the first edit box be active so I could start typing in that without having to click on it before.

@Override
public void init() {
  super.init();
  this.minecraft.keyboardHandler.setSendRepeatsToGui(true);

  TBDisplay = new EditBox(this.font, this.leftPos + 7, this.topPos + 11, 150, 20, Component.literal(""));
  this.addWidget(this.TBDisplay);
  
  //Initialize other components

  //Trying to set the focus
  TBDisplay.setCanLoseFocus(false);
  TBDisplay.active = true;
  TBDisplay.setFocus(true);
}

Setting the focus after initializing this and all other components on the screen highlights the edit box, but I still have to click on it before I can write something in it. How to make the edit box focused and writable without clicking on it? Thanks. 

Edited by RInventor7
Link to comment
Share on other sites

  • RInventor7 changed the title to Make EditBox active and focused when screen opened [1.19.2] [SOLVED]

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.