JOptionPane setMaximumSize with a JScrollPane as the object doesn't work
I am trying to use a JOptionPane for error messages. I'm trying to make the JOptionPane dialog be a minimum of 500x100 and a maximum size of 500x450 depending on the amount of text in the JTextArea inside the JScrollPane that's being passed into JOptionPane. I've tried both JOptionPane.showMessagePane(), and instantiating a JOptionPane and then setting its maximumSize, neither of which work as expected. Here is the relevant code:
public static void doCommonMessagePane( Component parent, String optMsg,
String title, int msgType )
JTextArea msg = new JTextArea( optMsg );
JScrollPane jsp = new JScrollPane( msg );
initOptionPaneComponents( msg, jsp );
Dimension maxSize =new Dimension(500, 450) ;
JOptionPane op = new JOptionPane(jsp, msgType);
op.setMaximumSize(maxSize);
op.revalidate();
op.setVisible(true);
//here is me also trying showMessageDialog
// JOptionPane.showMessageDialog(parent, jsp, title, msgType);
private static void initOptionPaneComponents( JTextArea ta, JScrollPane sp )
Color bg = UIManager.getColor( "Panel.background" );
Dimension jspSz = new Dimension( 500, 75 );
Dimension max = new Dimension( 500, 450 );
ta.setMargin( new Insets( 5, 10, 10, 5 ) );
ta.setColumns( 50 );
ta.setLineWrap( true );
ta.setWrapStyleWord( true );
ta.setEditable( false );
ta.setEnabled( false );
ta.setBackground( bg );
ta.setDisabledTextColor( Color.black );
ta.setFont( UIManager.getLookAndFeelDefaults().getFont( "Dialog" ) );
ta.setMaximumSize(max);
ta.setMinimumSize(jspSz);
sp.getViewport().add( ta );
//sp.setPreferredSize( jspSz );
sp.getViewport().setMaximumSize(max);
sp.getViewport().setMinimumSize(jspSz);
sp.setBorder( BorderFactory.createLoweredBevelBorder() );
sp.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED );
// sp.setPreferredSize( jspSz );
sp.setMinimumSize(jspSz);
sp.setMaximumSize( max );
}
When the JScrollPane is placed into the CENTER position the JOptionPane ignores the maxSize of both the JScrollPane and the JTextArea and stretches both of these out to 500x700 so that all text is visible. You still miss the basic concept.
The answer is it depends! First the size of the dialog needs to be determined.
If you use dialog.pack() then the preferred size of all components is used to determine the size of the dialog and the scrollpane will be whatever preferred size you gave it. If you leave the preferred size at (0, 0) then the scrollpane and text area will be invisible.
If you use dialog.setSize(???, ???), then the size of the scrollpane will be adjusted to fit the available space.
The amount of text in the text area is irrelevant in determining the size of the scrollpane. It is relevant in determining whether scrollbars will appear or not once the scrollpane is displayed.
If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
Don't forget to use the [Code Formatting Tags|http://forum.java.sun.com/help.jspa?sec=formatting], so the posted code retains its original formatting.
Similar Messages
-
I am having a problem with facebook notifications. The sound doesn't work but appears as a banner. I've tried everything but restoring the phone. Is this a phone problem or an app problem? Has anybody experienced this problem and were they able to correct it?
1) This is because of software version 1.1. See this
thread for some options as to how to go back to 1.0,
which will correct the problem...
http://discussions.apple.com/thread.jspa?threadID=3754
59&tstart=0
2) This tends to happen after videos. Give the iPod a
minute or two to readjust. It should now be more
accurate.
3) This?
iPod shows a folder icon with exclamation
point
4) Restore the iPod
5) Try these...
iPod Only Shows An Apple Logo and Will Not Start
Up
iPod Only Shows An Apple Logo
I think 3,4, and 5 are related. Try the options I
posted for each one.
btabz
I just noticed that one of the restore methods you posted was to put it into Disk Mode First rather than just use the resstore straight off, I Have tried that and seems to have solved the problem, If it has thank you. previously I have only tried just restoring it skipping this extra step. Hope my iPod stays healthy, if it doesnt its a warrenty job me thinks any way thanks again -
hello to everyone, I have a problem with my iPhone 5, the dynimic doesn't work... I didn't drop it and didn't contact with water...
so what should I do? please help me =(
P.S. may be I wrote with some mistakes, so I apologyze for itHello darkhanfromaktobe,
Thank you for using Apple Support Communities.
For more information, take a look at:
iPhone: Microphone issues
http://support.apple.com/kb/ts5183
Have a nice day,
Mario -
Trouble connecting to itunes store with my password on my ipod touch (2nd generation) but using the same apple id and password on my ipad2 I don't have a problem connecting to the store.
Need troubleshootingI have the same thing, same issues. Just came from Colorado using my iPad extensively with no problems.
Get back home, there is an update on my home computer for Airport Extreme to 7.5.2 which I updated. Also updates for iPad for 4.3.4 and now last night 4.3.5.
Still does not work. I have not taken the iPad to another network locally, but my understanding is that it is not a problem with the iPad but with Airport Extreme's update. I have done all the resets, restarts, and turning on and off Wifi on the iPad and that does not work.
I would have to assume Apple is working on it. Very frustrating since I am on my Mac Pro, iPhone 4, and other things and no problem. -
my iphone 5s with lightning to 30 pin adapter doesn't work in my audi A6 to play music, only to charge the phone. is there a fix for this?
Is the adapter the genuine Apple product or a copy
-
So, apparently I have two Apple IDs associated with my iPhone. One is an old aol address that got hacked and was shut down. Even aol doesn't recognize the email address anymore, and the password doesn't work. It's associated with my iCloud account, so now I can't access that account. My other Apple ID is with everything associated with my iPhone and everything works just fine. But now I can't get to my iCloud stuff. Has this ever happened to anyone else. The guy at the Apple store says he's never heard of it.
Does the alert refer to "Local Items?"
-
i have some problem with my computer because when i turn it up, the screen turns in a blue colour and the sound doesn't work and in this way i can't hear anything
Will u help me or not?
-
I have the latest 13" Macbook Pro with Retina Display. I just recently installed Windows 7 through Bootcamp assistant but when I am in Windows the internet doesn't work. How can I fix this??
I found where to download it in bootcamp, I just can't find my usb drive I will need to buy a new one and then give it a shot. I am sure I will be back to ask more questions... thanks for your help.
-
My iphone 5c the sound doesn't work only with earphone.
my iphone 5c the sound doesn't work it works only with earphone.
Hi there lavodette,
You may find the troubleshooting steps in the article below helpful.
iPhone: No sound or distorted sound from speaker
http://support.apple.com/kb/ts5180
-Griff W. -
The order doesn't work in my view with join between two lists. And now?
Hi,
I work with sharepoint 2010.
I did the join between two list follow this
post.
I did it and everything is ok, but the order doesn't work.
What can be it?
Thanks
K2rto'4 - Analista Sharepoint
"Hoje melhor do que ontem, amanhã melhor do que hoje!" 改 善Hi,
I've two lists in my view with join. The list A and the list B.
I'm ordering the view with the column list A.
The column list A it's a column for type lookup to list B's column.
In my view i'm ordering with the column list A of type lookup.
The view with join is not ordering in order growing.
I want the view will be ordering by order growing.
Do you understood?
Hugs
K2rto'4 - Analista Sharepoint
"Hoje melhor do que ontem, amanhã melhor do que hoje!" 改 善 -
Just bought my white iphone4 and after syncing with my computer the speaker doesn't work now. I tried reset and even restore and still does not work. Do I have to exchange?
Make sure the silent switch is not set to mute. If you can see the red dot, it is on mute.
It may think you have headphones plugged in, try plugging and unplugging a wired headset a few time.
The next step would be to restore as new.
If none of that works, a warranty exchange would be the resolution. -
Why the imsg doesn't work without a sim card with iOS 7???
Why the imsg doesn't work without a sim card with iOS 7???
If it worked for you using iOS 6, then it appears iOS 7 has made some changes. Was it working before?
-
How can i view excel on my iPhone 5s ?
with my ipad4 and the same ios7, viewing works without 3rd party AppDude or hot-spur,
Not fishy at all!!!! You really think I would have taken any more of my time to post a bogus rant? We'll no, it is unfortunately all true. I want to hear from anyone who is experiencing such problems not anyone else that wants to put there two cents in. I really don't need anymore hate or negativity. Just people's experiences because I feel like I am the only one having so many problems. Thank you
Yes, I have had some unfortunate bad luck to have so many problems at the same time, but some of them are just things you cannot do on the new OS.
Thank you again -
I have installed 0S5 but restoring the backup doesn't work. the following messages appears: An error accurred while restoring this iphone (-20), followed by another message: because the backup was corrupt or not compatible with iphone being restored (my iphone is 3GS), I tried restoring the factory settings and then restore the backup, but the same problems and I have lost all my contacts, pictures etc
Hi Ckuan,
Thanks a lot for your advice.
Deleting the correupted back up means to delete the information of one month since the last back up I made is one month ago.....right?
This back up I made right before I restored my iphone. During the restore however my OS was upgraded to 5.1.1. and reading the comments on the internet it seems I am not the only one whom experience this problem.
Can it be that if I downgrade my OS back to 5.1. the back up will not be considered as corrupted? If so, how do I downgrade the iphone?
Thanks in advance. -
I have two iphones in my house hold one syncs with my MAC Itunes the other doesn't is there a setting that casues the Iphone to stops syncing with Itunes?
You need to start over with Music. On the iPhone Music screen uncheck sync music. Also, on the Summary screen uncheck "Manually manage music and videos", then sync and it should clear off your phone.
Next, choose the music you want to sync. If you want to fit more on check "Convert higher bit rate songs to 128 kbps AAC". This will reduce quality slightly, but it won't be noticable unless you are using $300 headphones.
Maybe you are looking for
-
Values from Structure used in Form to be transferred to a Business Object
Hello, I have defined a structure (zcsks) in the workflow container. This structure is used in two forms (Change and Approve). With the approval (button pressed on approve form) the data entered in the structure zcsks has to be transferred to the bus
-
I want to change the iCloud account on my iPad from mine to my wife's
BUT I get a message saying that if I delete my account it will remove all data from iCloud! Which is not what I want as I want to continue to use my iCloud on my iPhone and remotely. There is no option in settings for changing the iCloud account, so
-
Need to upgrade from 10.7.5 to 10.8.6+ - no Mavericks
We have an immediate need to upagrade from 10.7.5 server to at least 10.8.6 SERVER today to support some Apple pro software we need to install / use today. We do not - emphasis do not - want to move to Marvericks or OS X server for mavericks. There a
-
Jewel case inserts are not printing full size
Hi all, This might be a more appropriate topic to one of the general forums, but I thought I'd try here first... I have a color printer (Lexmark z23) hooked up to an old PC, and wanted to print out a color copy of a jewel case insert. (I only have a
-
Iphoto 10 not able to download photos from kodak digital camera.
Working fine every time till recently and now the thumbnails have no image, just blank boxes and won't import new photos. error message returned "can't access photo" or similar