Note that there are some explanatory texts on larger screens.

plurals
  1. POMy custom JDialog appears minimized and JScrollPane's scroll disappears
    text
    copied!<p>I have created a basic swing program which displays an image in a <code>JDialog</code> box after it has been selected through a <code>JFileChooser</code>. I have used a <code>JScrollPane</code> inside the dialog box and a <code>JLabel</code> on which image is added as an icon, inside the pane.</p> <p>The following is the code I have used to construct the dialog box and its contents, the objects are already initialized with a simple new call:</p> <pre><code> jDialog1.setTitle("Image"); jDialog1.setModal(true); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jScrollPane2.setViewportView(jLabel1); </code></pre> <p>Netbeans has been used to build the GUI. </p> <p>The following is the code I have used to load and display the image:</p> <pre><code> int rval = jFileChooser1.showDialog(this, "Show"); File f = jFileChooser1.getSelectedFile(); jDialog1.setTitle(jDialog1.getTitle() + " : " + f.getName()); try { BufferedImage bf = ImageIO.read(f); jLabel1.setIcon(new ImageIcon(bf)); } catch (IOException ioe) { } jDialog1.setLocationRelativeTo(null); jDialog1.setVisible(true); jDialog1.pack(); </code></pre> <p>Though the image is loaded and displayed, the trouble is</p> <ul> <li><p>My dialog box appears in a minimized form in the upper left hand corner and i have to drag its corner to view the image. Including an image of the same.</p> <p><img src="https://i.stack.imgur.com/LLTn9.jpg" alt="enter image description here"></p></li> <li><p>The horizontal scroll of the scroll pane disappears long before the dialog box is fully extended and the image is fully displayed. Though the vertical scroll bar acts fine.</p></li> </ul> <p>I have tried setting size and preferred size of both <code>JDialog</code> and <code>JLabel</code> but the problems still persist.</p> <p>Thanx in advance!</p> <p><strong>Note:</strong> The horizontal scroll bar problem is solved by using the <code>pack()</code> method on the dialog box but the minimized dialog box is still there. Also, the dialog box now appears in the center of the screen as well.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload