| Author |
how to make my jtextfield smaller ?
|
naved momin
Ranch Hand
Joined: Jul 03, 2011
Posts: 675
|
|
i have put a jtextfield at the menubar by using createHorizontalGlue() to make the jtextfield at the right most part of my menubar
it appears at the right most part of my menubar but the width of that jtextfield doesn't changes
i try to make it shorter but that is not working can you have any other method to solve my problem
all i need is my jtextfield should have 30 columns but now it have more than 100 columns and strange thing is i m unable to change this size by invoking any methods.
|
The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
|
 |
Nitin Surana
Ranch Hand
Joined: Jan 21, 2011
Posts: 129
|
|
|
have you tried setMaximumSize() and setPreferredSize() both?
|
 |
naved momin
Ranch Hand
Joined: Jul 03, 2011
Posts: 675
|
|
Nitin Surana wrote:have you tried setMaximumSize() and setPreferredSize() both?
non of them are working in my case
next what should i do ?
|
 |
Nitin Surana
Ranch Hand
Joined: Jan 21, 2011
Posts: 129
|
|
|
Which layout manager are you using? We need to have a look at your code, in order to figure out what is going wrong.
|
 |
naved momin
Ranch Hand
Joined: Jul 03, 2011
Posts: 675
|
|
Nitin Surana wrote:Which layout manager are you using? We need to have a look at your code, in order to figure out what is going wrong.
its a big project and lot of code so i cant put the code here
but as far as layout is concern i guess menu bar uses box layout isn't it ?
and i m adding jtextfield to menu bar
when ever i put textfield in jscrollpane it appears at the right hand side but with a long width
but if i remove jscrollpane and just add the jtextfield into menu bar the white area appears till help menu or sometimes overlap help menu
but my search word inside search textfield remain at the right most part of menubar
|
 |
Nitin Surana
Ranch Hand
Joined: Jan 21, 2011
Posts: 129
|
|
you can do one thing :
put your jtextfield within a JPanel, now that JPanel is the one which will have large size, but that won't be visible and then you can control the layout of JPanel and hence you can control the size of the jtextfield.
|
 |
Rob Camick
Ranch Hand
Joined: Jun 13, 2009
Posts: 1788
|
|
its a big project and lot of code so i cant put the code here
We don't care about your project, only the part you are having problems with. So we only need the part for creating a frame and adding a simple meubar to the frame with a text field.
The code to demonstrate your problem should be about 15-20 lines of code. This is called an SSCCE.
|
 |
naved momin
Ranch Hand
Joined: Jul 03, 2011
Posts: 675
|
|
|
done thanks nitin
|
 |
Digen Mahara
Greenhorn
Joined: Dec 23, 2011
Posts: 23
|
|
to make your textfields smaller use setPrefferedSize(new Dimension(width,height));
eg : to set the height = 25 and width= 30
|
To every Tunnel there is always a way out
So keep Trying...
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
But keep in mind that the layout manager may ignore it. The center component of a BorderLayout will stretch all ways if the container is enlarged.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
yasser kantour
Greenhorn
Joined: Jun 13, 2012
Posts: 2
|
|
you have to add a JToolBar.Separator
try this code before you add the textField and the "search" jButton
yourMenuBar.add(new JToolBar.Separator(new Dimension(int here the length of the separating area,0));
yourMenuBar.add(yourTextField);
yourMenuBar.add(yourSearchButton);
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32651
|
|
yasser kantour, welcome to the Ranch
|
 |
yasser kantour
Greenhorn
Joined: Jun 13, 2012
Posts: 2
|
|
|
Thank uuuu
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4163
|
|
yasser kantour wrote:Thank uuuu
Please UseRealWords <-- link
|
luck, db
There are no new questions, but there may be new answers.
|
 |
 |
|
|
subject: how to make my jtextfield smaller ?
|
|
|