Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Minimum size on JDialogs?

 
dave taubler
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Does anyone know if there is a minimum size for JDialog that Swing itself enforces?

I am attempting to create a toolbar similar to one that you'd find in, say, Photoshop (the Photoshop tools palette, specifically). I want the width to be pretty narrow; like the Photoshop tools palette, it should be just two small buttons wide. When my toolbar is "docked", the width is just the way I want it. But when the user drags the toolbar away and it becomes floating, the width is too wide, despite my best efforts.

As an experiment, I also created a simple app with a JDialog, and set the JDialog's preferred, minimum, and maximum width to 20 pixels (IIRC, JToolbar uses a JDialog instance when it becomes floating). However, the JDialog still appeared much wider than that.

The same issue occurs for me in both Windows XP Java 5 and 6, and Mac OSX Java 5.

So does anyone know if Swing enforces a minimum size for JDialogs? And can anything be done about it?

Thanks in advance.
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it needs at least the width to show the title bar, and including the close button that's over 20 pixels it seems. You could try a JWindow but then you lose the title bar completely.
 
dave taubler
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tip. It would probably mean digging into the JToolBar's ToolBarUI implementation to do something like that, but hey, I guess I'm up for the challenge.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you use
JDialog.setDefaultLookAndFeelDecorated(true);
and
dialog.setMinimumSize(new Dimension(0,0));

you can have any width you want
 
Shiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!