• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to make my jtextfield smaller ?

 
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 129
Netbeans IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
done thanks nitin
 
Greenhorn
Posts: 23
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yasser kantour, welcome to the Ranch
 
yasser kantour
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank uuuu
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

yasser kantour wrote:Thank uuuu


Please UseRealWords <-- link
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic