Hi, I have a focus problem.
mytext= new JTextField(); mytext.requestFocus(true); gc.fill =GridBagConstraints.HORIZONTAL ; gc.gridx =3; gc.gridy=4; gbl.setConstraints(mytext,gc); jContentPane.add(mytext);
I tried
mytext.requestFocus();
too
and how can I automatically select text in the text box so that the text is marked?
From Swing Tutorial
If you want to make sure that a particular component receives focus when you first turn on the window, you can call the requestFocusInWindow method on the component after the component is implemented, but before the frame is displayed. The following code example shows how this operation can be performed:
//...Where initialization occurs... JFrame frame = new JFrame("Test"); JPanel panel = new JPanel(new BorderLayout()); //...Create a variety of components here... //Create the component that will have the initial focus. JButton button = new JButton("I am first"); panel.add(button); frame.getContentPane().add(panel); //Add it to the panel frame.pack(); //Realize the components. //This button will have the initial focus. button.requestFocusInWindow(); frame.setVisible(true); //Display the window.
Regarding the selection of all the text you should use ...
mytext.selectAll();
, , requestFocus , jContentPane.
Source: https://habr.com/ru/post/1742730/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1742725/redirecting-multiple-stdouts-to-single-file&usg=ALkJrhg1owtJWTy0E9sV5hgy6-O28DOfNQHow to save case with http.get? - ruby | fooobar.cominitialization of structures using user information - c ++call transferFocus or requestFocus? - javaHow can I prevent a user from going to the previous page - asp.netИнициализация "новых пользователей" в Rails - ruby-on-railsTechnologies Used in Remote Administration (Non-RD) Applications - c #Original home control - version-controlusing Windows Media Encoder to record a screen - windowsFuture client-server code verification? - dnsAll Articles