Hey I was just wondering if there is a way to set JTextField width for example 50% of the screen size. I know how to get the dimensions of screen just JTextField sets it to number of characters not pixels
textfield = new JTextField(“Way hello there”, 20);
is there a way to do this ?
Setting the size of
JTextFieldin pixels leads you down the path of using absolute positioning which is generally not advisable. From Doing Without a Layout ManagerHave a look at the functionality offered by existing layout managers and avoid using the setXXXSize() component methods. For example,
GridLayout( or evenGridBagLayout) can be used to size aJTextFieldwidth to 50% of a frame client area.