Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

JDialog of the same size as jTextField Swing in Java  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
0
down vote
favorite
I'm using a "JSuggestField" which is a modification of JTextField that's capable of showing suggestions, the thing is it uses a JDialog to show those suggestions and I need it to be shown always as wide as the jTextField (so if jTextField becomes wider then JDialog should change with it)

Here's my code, see if you can lend me a hand

https://pastebin.com/wAWfTVDG
 
Marshal
Posts: 59786
188
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please tell the people on SO that you have posted here too. Please supply some short code that shows the problem: it should be an SSCCE. People are reluctant to go to external links to read the code, particuallrly if it as long as what you had on SO.
I could see one comment on the SO thread about setVisible(). You would usually only call that method on a frame, but it is best to call it last, after all child components have been added, given sizes, etc. We need to know the relevant details about one problem and one problem only before we can help.
 
Seruhio Mendoza
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
https://hastebin.com/imacikepix.java

Yes, I tried to get the size of the JTextField and assign it to the jdialog just before the d.setVisible(true); in this way d.setPreferredSize(this.getSize());

In fact if I look at the size of the jdialog (d.getSize()) the size has changed but nothing happens visually.

The jdialog size only changes when I call setPreferredSize when I start the program.

I need it to change and it's always the same size as the jtextfield.



Thanks for your response, I have already done what you asked for.
 
Master Rancher
Posts: 3275
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the source code here in this thread?  Not as a link.
 
Seruhio Mendoza
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Norm Radder
Master Rancher
Posts: 3275
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see a main method.  How can the posted code be compiled and executed for testing to see the problem?
 
Campbell Ritchie
Marshal
Posts: 59786
188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you subclassing a text component? Why have you given it data as fields? Why are you passing listeners to a parent component? Why does a listener on a parent component affect child dialogues? Why are you setting a dialogue visible or not? That can cause a dialogue to disappear without being dismissed, which will cause you not end of problems if it is a modal dialogue.
I am not at all sanguine about that code, I am afraid.
 
Master Rancher
Posts: 2758
93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A quick question: in what way is your class different from a JCombobox?
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!