JDialog: Repaint does not work as wanted when called a second time

Hi,
I have created a JDialog with a More/Less Details button which, when invoked, shows or not shows a JScrollPane with a JEditorPane and resizes the dialog window to make space for that extra component or to take away that space.
It works fine the first time I invoke the JDialog (see main method). But if I invoke it a second time and want to see the details the details JScrollPane is not fully shown.
I have experimented with repaint and revalidate on different panels but to no avail.
I am quite new to Swing, what am I misunderstanding? Is my Close-button not tidying up properly?
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.awt.*;
class Tester extends JDialog {
    private static int totalWidth = 200;
    private static int totalHeight = 100;
    private static int detailsPanelHeight = 200;
    public Tester() {
     super();
    public static int createAndShowGUI() {
     Tester td = new Tester();
     return td.doGUI();
    public int doGUI() {
        //Create and set up the window.
     setPreferredSize(new Dimension(totalWidth, totalHeight+detailsPanelHeight));
     setModal(true);
     setResizable(false);
     setTitle("Tester");
     setAlwaysOnTop(true);
     final Container mainPane = getContentPane();
     mainPane.setLayout(new FlowLayout());
     // *** Panel for details
     final JEditorPane detailsText = new JEditorPane("text/html", "<HTML>Some <i>html</i>.</HTML>");
     final JScrollPane detailsPanel = new JScrollPane(detailsText);
     detailsPanel.setBorder(new TitledBorder("Details"));
     detailsText.setEditable(false);
     detailsPanel.setPreferredSize(new Dimension(totalWidth-100, detailsPanelHeight));
     detailsPanel.setVisible(false);
     // *** Panel for Info
     final JToggleButton detailsBtn = new JToggleButton("More Details");
     detailsBtn.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              if (detailsBtn.isSelected()) {
               detailsBtn.setText("Less Details");
               detailsBtn.repaint();
               detailsPanel.setVisible(true);
               setBounds(getX(), getY(),
                      getWidth(), getHeight()+detailsPanelHeight);
               // Also tried detailsPanel.revalidate(), mainPane.revalidate/repaint()
               // to no avail
               detailsPanel.repaint();
              else {
               detailsBtn.setText("More Details");
               detailsBtn.repaint();
               detailsPanel.setVisible(false);
               setBounds(getX(), getY(),
                      getWidth(), getHeight()-detailsPanelHeight);
               detailsPanel.repaint();
     // *** Panel for buttons
     JPanel btnPanel = new JPanel();
     mainPane.add(btnPanel);
     mainPane.add(detailsPanel);
     // Allow Button
     JButton allowBtn = new JButton("Close");
     allowBtn.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              setVisible(false);
              dispose();
     btnPanel.add(allowBtn);
     btnPanel.add(detailsBtn);
        //Display the window.
        pack();
     setBounds(getX(), getY(), totalWidth, totalHeight);
        setVisible(true);
     return 1;
    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
          public void run() {
              // Run once and you can see details in nice window
              System.err.println(Tester.createAndShowGUI());
              // Run twice and switching on details shows an empty space
              System.err.println(Tester.createAndShowGUI());
}

Replace your action preformed with this:
public void actionPerformed(ActionEvent e) {
    if (detailsBtn.isSelected()) {
     detailsBtn.setText("Less Details");
     setSize(new Dimension(
            getWidth(), getHeight()+detailsPanelHeight));
     detailsPanel.setVisible(true);
    else {
     detailsBtn.setText("More Details");
     detailsPanel.setVisible(false);
     setSize(new Dimension(
                 getWidth(), getHeight()-detailsPanelHeight));
    validate();
}

Similar Messages

  • Macbook Pro 2011 DVI HDMI out does not work with TV when the power cable is connected

    My Macbook Pro (Early 2011) DVI HDMI out does not work with TV when the power cable is connected. If get the blue screen and then can use the macbook but nothing is displayed on the TV. If i go into display I can see that there are two screens but nothing displayed on the TV. If i take the power cable out at this point the TV shows the second desktop as expected. If i then reconnect the cable, the screen flickers, as though it is being affected by the power cable, and the screen goes blank on the TV. Only if i remove the DVI cable do i get the blue screen again. If i remove the power cable and reconnect it will do it every single time, so i cannot see it being a TV issue or a minor glitch.
    I have had this working previously but at the minute it seems to not be playing ball....any thoughts
    Thanks
    Dan

    BUMP
    Any ideas?

  • Keyboard plugs into the back of my display does not work? but when I plug the keyboard into my MacBook Pro it works fine? is it my display Monitor?

    My keyboard plugs into the back of my display monitor it does not work? but when I plug the keyboard into my MacBook Pro it works fine? is it my display Monitor?

    Try:
    - Resetting the iPod:
    Reset iPod touch:  Press and hold the On/Off Sleep/Wake button and the Home
    button at the same time for at least ten seconds, until the Apple logo appears.
    - Resetting network settings: Setting>General>Reset>Reset Network Settings

  • Itunes is not working on my mac. I'm trying to redeem a gift card and everytime I enter my password it does not work.  Also, when I try and browse songs, everything is blank

    HELP!
    Itunes is not working on my mac. I'm trying to redeem a gift card and everytime I enter my password it does not work.  Also, when I try and browse songs, everything is blank

    It's been a while but it should work on a Mac because Macs can read Windows formatted devices. Otherwise, you can perform a restore operation to return it to the Mac format. If you go to support.apple.com/manuals/ you can find a copy of the user manual for the model you have in which this is all explained.

  • In "Show more Bookmarks" if I right click does not work (I want to open in a new tab)

    This is using Mac Firefox current version. I use lots of tabs and don't have space for all of them so there is a >> at the right end for clicking and displaying the rest of them. If I click and display list and highlight one of them, the right click does not work - I want to open in a new tab not use the existing - there are no menu options displayed on these tabs. The tabs across the top work fine for this

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    * https://support.mozilla.com/kb/Safe+Mode
    If it does work in Safe-mode then disable all extensions and then try to find which is causing it by enabling one at a time until the problem reappears.
    * Use "Disable all add-ons" on the [[Safe mode]] start window to disable all extensions.
    * Close and restart Firefox after each change via "File > Exit" (Mac: "Firefox > Quit"; Linux: "File > Quit")
    In Firefox 4 you can use one of these to start in <u>[[Safe mode]]</u>:
    * Help > Restart with Add-ons Disabled
    * Hold down the Shift key while double clicking the Firefox desktop shortcut (Windows)
    * https://support.mozilla.com/kb/Troubleshooting+extensions+and+themes

  • My Creative Cloud does not work anymore. When I try to reinstall it I receive the message "AAM cannot initialise". I have tried all the instructions but it still does not work. Robert

    My Creative Cloud does not work anymore. When I try to reinstall it I receive the message "AAM cannot initialise". I have tried all the instructions but it still does not work. Robert

    Try perform below steps.
    Open task manager by pressing Ctrl + Shift + Esc  keys. Click on more details if the option available.
    Then end all Adobe related processes, including Creative Cloud and Coresync ( if running )
    Then hold windows key on your keyboard and Press R key.
    It will open Run window
    In Run window, type Appdata and click on Ok
    Open Local > Adobe folders
    Delete AAMUpdater and OOBE folders
    Then navigate to C:\Program Files (x86)\Common Files\Adobe
    Delete Adobe Application Manager and OOBE folders
    Go back to Program Files (x86) and Open Adobe folder
    Try deleting Adobe Creative Cloud folder, if it is not allowing rename it to Adobe Creative Cloudold
    Download and install Creative Cloud App from below link
    https://creative.adobe.com/products/download/creative-cloud
    Then check

  • What has happened to the iPad 2 finger select and drag technique? Since upgrading to iOS7 it does not work? I used this all the time to select multple images, approx 75  from an SD card containing 1000  images. Its painful indvidually selecting the images

    What has happened to the iPad 2 finger select and drag technique?
    Since upgrading to iOS7 it does not work?
    I used this all the time to select multple images, approx 75  from an SD card containing 1000  images. Its painful indvidually selecting the images

    What would you like us to tell you? If it doesn't work, there is nothing that we users can do about it.
    Please submit your feature request to Apple at this link: http://www.apple.com/feedback

  • Updated to IOS 7.1 and now my "Call Waiting" does not work, nor will the "Call Waiting" indicator stay on..... Any help?

    Updated to IOS 7.1 and now my "Call Waiting" does not work, nor will the "Call Waiting" indicator stay on..... Any help?

    Settings > General > Reset > Reset Network Settings

  • Silverlight 5 binding on a property with logic in its setter does not work as expected when debug is attached

    My problem is pretty easy to reproduce.
    I created a project from scratch with a view model.
    As you can see in the setter of "Age" property I have a simple logic.
        public class MainViewModel : INotifyPropertyChanged
                public event PropertyChangedEventHandler PropertyChanged;
                private int age;
                public int Age
                    get
                        return age;
                    set
                        /*Age has to be over 18* - a simple condition in the setter*/
                        age = value;
                        if(age <= 18)
                            age = 18;
                        OnPropertyChanged("Age");
                public MainViewModel(int age)
                    this.Age = age;
                private void OnPropertyChanged(string propertyName)
                    if (this.PropertyChanged != null)
                        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    In the MainPage.xaml 
         <Grid x:Name="LayoutRoot" Background="White">
                <TextBox 
                    Text="{Binding Path=Age, Mode=TwoWay}" 
                    HorizontalAlignment="Left"
                    Width="100"
                    Height="25"/>
                <TextBlock
                    Text="{Binding Path=Age, Mode=OneWay}"
                    HorizontalAlignment="Right"
                    Width="100"
                    Height="25"/>
            </Grid>
    And MainPage.xaml.cs I simply instantiate the view model and set it as a DataContext.
        public partial class MainPage : UserControl
            private MainViewModel mvm;
            public MainPage()
                InitializeComponent();
                mvm = new MainViewModel(20);
                this.DataContext = mvm;
    I expect that this code will limit set the Age to 18 if the value entered in the TextBox is lower than 18.
    Scenario: Insert into TextBox the value "5" and press tab (for the binding the take effect, TextBox needs to lose the focus)
    Case 1: Debugger is attached =>
    TextBox value will be "5" and TextBlock value will be "18" as expected. - WRONG
    Case 2: Debugger is NOT attached => 
    TextBox value will be "18" and TextBlock value will be "18" - CORRECT
    It seems that when debugger is attached the binding does not work as expected on the object that triggered the update of the property value. This happens only if the property to which we are binding has some logic into the setter or getter.
    Has something changed in SL5 and logic in setters is not allowed anymore?
    Configuration:
    VisualStudio 2010 SP1
    SL 5 Tools 5.1.30214.0
    SL5 sdk 5.0.61118.0
    IE 10
    Thanks!                                       

    Inputting the value and changing it straight away is relatively rare.
    Very few people are now using Silverlight because it's kind of deprecated...
    This is why nobody has reported this.
    I certainly never noticed this problem and I have a number of live Silverlight systems out there.
    Some of which are huge.
    If you want a "fix":
    private void OnPropertyChanged(string propertyName)
    if (this.PropertyChanged != null)
    //PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    Storyboard sb = new Storyboard();
    sb.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 100));
    sb.Completed += delegate
    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    sb.Begin();
    The fact this works is interesting because (I think ) it means the textbox can't be updated at the point the propertychanged is raised.
    Please don't forget to upvote posts which you like and mark those which answer your question.
    My latest Technet article - Dynamic XAML

  • Deleting cookies, either one at a time or all, does not work; they reappear when I go back to view them. This is a critical privacy problem!

    Removing cookies does not work, either one at a time, or remove all. I tried from history and from the options screen. They appear to go away but when I go back in they are all back again. This is happening in the latest version that was automatically updated.'''bold text'''

    Do you have an extension like TACO (Abine) or TrackerBlock that maintains a set of OPT-OUT cookies?
    * Targeted Advertising Cookie Opt-Out (TACO): https://addons.mozilla.org/firefox/addon/targeted-advertising-cookie-op/
    * TrackerBlock: https://addons.mozilla.org/firefox/addon/trackerblock/
    * Beef Taco (Targeted Advertising Cookie Opt-Out): https://addons.mozilla.org/firefox/addon/beef-taco-targeted-advertising/
    In that case you need to remove such an extension to get rid of those cookies.

  • Lion Install does not work, says "This disk is used for Time Machine backups"

    I'm having trouble installing Lion onto my macbook pro intel core 2 duo. 
    I am backing up my computer with an external drive using TimeMachine, but i've disconnected it.  Also i'm running SL 10.6.8  
    I have a windows 7 partition that was created with boot camp.
    I've tried to make sure everything is all ready for lion but when I go to install lion it says "This disk is used for Time Machine backups" and the hard drive is grayed out.
    Same problem as this guy: https://discussions.apple.com/thread/3190321?start=0&tstart=0
    I'm hearing that a file called "Backups.backupdb" is on the top level of the hard drive, but I see no such file.  I've looked at the invisible files and I cant find it.
    I've also created a bootable flash copy of the lion install but that does not work It gives me the same message "This disk is used for time Machine backups".

    "Backups.backupdb" if the file in Time Machine.  As the discussion says, you have to find that file and trash it.  Try spotlight to locate it.  If that does not work, down load OmniDiskSweeper from the Internet (free) and go through an organized search to find "Backups.backupdb".  If that takes too long or is too tedious, then if you have everything backed up, erase the HDD and start from square one.
    Ciao.

  • Continuity:  Microphone does not work during Continuity/iPhone calls

    MacPro, Yosemite (10.10.2)
    iPhone 4S, 8.1.3
    Continuity has worked fine for me in the past.  However, I now have an issue where I can make calls from my Mac....they go through with trouble....but my microphone is not passed through to the call.  I can hear them...they cannot hear me.
    Voice-to-text, FaceTime, and Skype all work fine, so I know that my microphone is not having troubles.
    This is the first time I have used this since upgrading to 10.10.2 or ios 8.1.3.  So, possibly related...possibly not.
    Ideas?

    Errr.....sorry guys. I mis-typed something....
    When I make a call, it goes through WITHOUT any trouble.  No trouble that is except nobody can hear me.

  • Dialog Box does not function when called a second time

    I have created a dialog box that only seems to work once in a larger application. The box is designed to be a MatLab code debugger. My idea was to allow a user to interactively create/debug Matlab code from LabView using ActiveX automation. Anyway, I have created a test vi that uses this dialog box twice. The first time it is called it functions as expected, but the second time nothing on the front panel (of the dialog box) responds and I cannot close the window or interrupt the vi. I am using LabVIEW 7.0 on Windows 98. Please see the attached vi's. MatlabDebugger.vi is the dialog that's causing the problem. Matlabx2.vi is the sub vi that handles the ActiveX automation. Debuggertest.vi is the test v
    i in which the dialog will not word a second time.
    Thanks in advance for any help or suggestions.
    Attachments:
    Debuggertest.vi ‏51 KB
    MatlabDebugger.vi ‏303 KB
    Matlabx2.vi ‏361 KB

    The problem is caused by the nested event structures; you have an event structure inside an event structure, acting on the same controls. When the main one reacts to the cancel the other one get's stuck...so on the next call the main event structure just halts due to the stuck event structure inside it. It's not obvious why this is a fault, you may be able to spot it now that you're on the track though.
    MTO

  • Color picker does not work, " program error when I click, photoshop cc

    I am user of photoshiop cc and it worked fine until several days ago but suddenly it shows " program error " when I click color picker, and I can not use changing color. Please help me to resolve this issue.

    There was a bug with photoshop CC concerning the color picker and its swatches. Make sure you have the latest version and then if it still exists, reset your tools in the upper left hand corner which would be the very first icon in the top tool bar. That should fix it. If not let us know and maybe someone can think of something else.

  • Background saving does not work in background when it is part of an action

    I LOVE the new background saving function. I do agree with a nother post that it would be nice to have some kind of progress bar when in full screen mode though.
    The other thing I noticed is that if you make an action that has a "Save" command in it, it will NOT do that in the background but rather in the way of previous versions, with the progress bar window pop-up.

    Agree

Maybe you are looking for

  • Transfer music from one Apple account to another

    Is it possible to transfer purchased songs from one Apple account to another? I have some music on my account that I have downloaded for someone who did not have an account. Now, they have an account, and I want to transfer their music to their accou

  • Fiscal year variant Z1 is not maintained for calendar year 2012

    I am getting this error while scheduling infopackage for 2lis_02_HDR. Fiscal year variant Z1 is not maintained for calendar year 2012 PLease let me know how to solve thhe issue. Thanks, harika.

  • System not going to sleep...

    Hello All, I have a Macbook 13.3, 2.16G's, 2G's or RAM running OS X ver. 10.5.5 all up to date, .. ... system issued to always go to sleep with no problem at around the time set up in energy saver prefs pane. Now is not. configuration hasn't been cha

  • StarOffice 8 (Product 6) Update to Product 7 Error

    Hi, I tried to update as prompted by auto-update feature. But after I have finished downloading and saved the file 120187-10 (Signed Patch). But when I opened the file, a Java virtual machine launcher window pop up and with message stated Invalid or

  • FM to read CSN short text and Date of its creation

    Hello Experts,         I need an function module that takes CSN number as input and returns the short text and date of creation of the CSN. If you know of any such function module then please let me know.        Thanks in advance Regards, Prafful