This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to make my jtextfield smaller ?

 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nitin Surana
Ranch Hand
Posts: 129
Java Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you tried setMaximumSize() and setPreferredSize() both?
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
Java Netbeans IDE Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 129
Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2580
9
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
done thanks nitin
 
Digen Mahara
Greenhorn
Posts: 23
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to make your textfields smaller use setPrefferedSize(new Dimension(width,height));

eg : to set the height = 25 and width= 30

 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
yasser kantour
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48917
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yasser kantour, welcome to the Ranch
 
yasser kantour
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank uuuu
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yasser kantour wrote:Thank uuuu

Please UseRealWords <-- link
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic