File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JList and closing frames Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JList and closing frames" Watch "JList and closing frames" New topic

JList and closing frames

Bron Czimes
Ranch Hand

Joined: May 09, 2004
Posts: 44
hi everyone,
got a coupla questions, if you can answer them

I was just wondering if there is an option, when using a JList, to make the listbox a little bit wider, so that the items in the listbox can have a little bit of "breathing space". At the moment, all I seem to be able to get to work, is putting spaces around the actual items, before I put them into the list box. Surely theres a better way of doing it!!

And the second question.... when a user clicks the X to close a frame, I'm giving them the option to cancel the action if they made a mistake. I'm using a dialog box to do this. I've been fiddling with Dialog.YES_OPTION and Dialog.NO_OPTION to determine what the user wants before closing the frame but it doesn't seem to be working. It keeps giving me an error about boolean and int types.
code is

Thanks for your help.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

I looked into your first question a little bit. Thought that by using a custom ListCellRenderer you could somehow specify the margin between the text and the border of a JLabel, but looking at the API I am not sure this is even possible.

As far as your 2nd problem, the code below does what you expect.

GenRocket - Experts at Building Test Data
Bron Czimes
Ranch Hand

Joined: May 09, 2004
Posts: 44
ok i tried that but modified it in a GUI format.

but now it closes the whole program regardless of which button i press.
Bron Czimes
Ranch Hand

Joined: May 09, 2004
Posts: 44
ah, not to worry, i've worked it out
thanks for your help Gregg
I agree. Here's the link:
subject: JList and closing frames
It's not a secret anymore!