Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do I pass dimensions to a Swing JPanel creator class?
    primarykey
    data
    text
    <p>I am trying to pass dimensions to a Java Swing JPanel creator class. No luck so far. I even put the <code>contentPane.setPreferredSize(new Dimension(intWidth, intHeight));</code> in a try / catch block and I did not get any system output. I am passing a pretty substantial value, <code>frame.setContentPane(ContentPaneCreator.createContentPane("darkseagreen", 800, 255));</code>, but the application is still as small as the components it is around. What can be done to fix it? Thanks.</p> <pre><code>import java.awt.Container; import java.awt.Dimension; import javax.swing.JPanel; public final class ContentPaneCreator { public static Container createContentPane(String color, int intWidth, int intHeight) { JPanel contentPane = new JPanel(); // Pass the colour contentPane.setBackground(ColorFactory.getInstance().getColor(color)); // Pass the dimensions try { contentPane.setPreferredSize(new Dimension(intWidth, intHeight)); } catch (Exception ex) { System.out.println(ex); } return contentPane; } } </code></pre> <p>StickyNotes()</p> <pre><code>import java.awt.BorderLayout; import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; public class StickyNotes extends JFrame { private static final long serialVersionUID = 1L; public static String appName; public static String fileConfirmSave; public static String txtConfirmChange; private void createStickyNotesGUI() { ConfigProperties config = new ConfigProperties(); // ConfigProperties config2 = new ConfigProperties().getFileIn(); appName = config.getConfigProperties("appName").toUpperCase(); fileConfirmSave = config.getConfigProperties("fileConfirmSave"); txtConfirmChange = config.getConfigProperties("txtConfirmChange"); // Create and set up the window. JFrame frame = new JFrame(); frame.setTitle(appName); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new FlowLayout(FlowLayout.LEFT)); /* BEGIN ROOT Pane: */ /* BEGIN Layered Pane: */ // Add Main Menu MainMenuBar mainMenu = new MainMenuBar(); frame.setJMenuBar(mainMenu.createMainMenuBar(frame)); /* BEGIN CONTENT Pane(s): */ // Add JPanel Content // can I pass a layout object? frame.setContentPane(ContentPaneCreator.createContentPane("darkseagreen", 800, 255)); // Add Tool Bar /* needs to be run AFTER we .setContentPane() in order for it to be layerd on top */ ToolBarCreator toolBar = new ToolBarCreator(); frame.getContentPane().add(toolBar.createToolBar(), BorderLayout.NORTH); // TODO /* * Pass dynamic color values to LabelCreator() once you get * newStickyNote() working */ frame.getContentPane().add( LabelCreator.createLabel(frame, "Java Swing", "purple"), BorderLayout.NORTH); // Display the window here with JFrame// //frame.setExtendedState(JFrame.MAXIMIZED_BOTH); // TODO /* set configuration to remember frame size */ frame.pack(); frame.setVisible(true); } public void doExit(JFrame frame) { boolean fDirty = true; if (fDirty) switch (JOptionPane.showConfirmDialog(StickyNotes.this, fileConfirmSave, txtConfirmChange, JOptionPane.YES_NO_OPTION)) { case JOptionPane.YES_OPTION: // if (doSave()) frame.dispose(); break; case JOptionPane.NO_OPTION: frame.dispose(); } else frame.dispose(); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new StickyNotes().createStickyNotesGUI(); } }); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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