开发者

Why Java jFrame setResizable() is failling to act?

This code is automatically generated by Netbean 6.8 GUI builder. The default application was not contained in a jFrame! It was in jPanel only which I didn't know how to make it none re-sizable. so I added a jFrame to contain all of them and although I set its setResizable(); to False...it still re-sizable! Here is the code:

    import org.jdesktop.application.Action;
    import org.jdesktop.application.ResourceMap;
    import org.jdesktop.application.SingleFrameApplication;
    import org.jdesktop.application.FrameView;
    import org.jdesktop.application.TaskMonitor;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Timer;
    import javax.swing.Icon;
    import javax.swing.JDialog;
    import javax.swing.JFrame;

    public class BOSSConverterView extends FrameView {

    public BOSSConverterView(SingleFrameApplication app) {
    super(app);
    JDialog dlg = new JDialog();
    dlg.setUndecorated(true);
    dlg.setModal(true);
    dlg.setLayout(new BorderLayout());
    ImageIcon img = new ImageIcon(getClass().getResource("splash.png"));
    dlg.add(img, BorderLayout.CENTER);
    dlg.setLocationRelativeTo(null);
    dlg.setVisible(true);        
    initComponents();
    ResourceMap resourceMap = getResourceMap();
    int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
    messageTimer = new Timer(messageTimeout, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            statusMessageLabel.setText("");
        }
    });
    messageTimer.setRepeats(false);
    int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
    for (int i = 0; i < busyIcons.length; i++) {
        busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
    }
    busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
            statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
        }
    });
    idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
    statusAnimationLabel.setIcon(idleIcon);
    progressBar.setVisible(false);

    // connecting action tasks to status bar via TaskMonitor
    TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
    taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            String propertyName = evt.getPropertyName();
            if ("started".equals(propertyName)) {
                if (!busyIconTimer.isRunning()) {
                    statusAnimationLabel.setIcon(busyIcons[0]);
                    busyIconIndex = 0;
                    busyIconTimer.start();
                }
                progressBar.setVisible(true);
                progressBar.setIndeterminate(true);
            } else if ("done".equals(propertyName)) {
                busyIconTimer.stop();
                statusAnimationLabel.setIcon(idleIcon);
                progressBar.setVisible(false);
                progressBar.setValue(0);
            } else if ("message".equals(propertyName)) {
                String text = (String)(evt.getNewValue());
                statusMessageLabel.setText((text == null) ? "" : text);
                messageTimer.restart();
            } else if ("progress".equals(propertyName)) {
                int value = (Integer)(evt.getNewValue());
                progressBar.setVisible(true);
                progressBar.setIndeterminate(false);
                progressBar.setValue(value);
            }
        }
    });
}

@Action
public void showAboutBox() {
    if (aboutBox == null) {
        JFrame mainFrame = BOSSConverterApp.getApplication().getMainFrame();
        aboutBox = new BOSSConverterAboutBox(mainFrame);
        aboutBox.setLocationRelativeTo(mainFrame);
    }
    BOSSConverterApp.getApplication().show(aboutBox);
}

/** This method is called from within the constructor to
 * initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

    mainFrame = new javax.swing.JFrame();
    mainPanel = new javax.swing.JPanel();
    jTabbedPane1 = new javax.swing.JTabbedPane();
    jDesktopPane1 = new javax.swing.JDesktopPane();
    jFormattedTextField1 = new javax.swing.JFormattedTextField();
    jFormattedTextField2 = new javax.swing.JFormattedTextField();
    jDesktopPane2 = new javax.swing.JDesktopPane();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextArea1 = new javax.swing.JTextArea();
    jScrollPane2 = new javax.swing.JScrollPane();
    jTextArea2 = new javax.swing.JTextArea();
    jButton1 = new javax.swing.JButton();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    statusPanel = new javax.swing.JPanel();
    javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
    statusMessageLabel = new javax.swing.JLabel();
    statusAnimationLabel = new javax.swing.JLabel();
    progressBar = new javax.swing.JProgressBar();
    menuBar = new javax.swing.JMenuBar();
    javax.swing.JMenu fileMenu = new javax.swing.JMenu();
    openFileMenuItem = new javax.swing.JMenuItem();
    javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
    javax.swing.JMenu helpMenu = new javax.swing.JMenu();
    javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();

    mainFrame.setName("mainFrame"); // NOI18N
    mainFrame.setResizable(false);

    mainPanel.setMaximumSize(new java.awt.Dimension(400, 400));
    mainPanel.setName("mainPanel"); // NOI18N

    org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(bossconverter.BOSSConverterApp.class).getContext().getResourceMap(BOSSConverterView.class);
    jTabbedPane1.setBackground(resourceMap.getColor("jTabbedPane1.background")); // NOI18N
    jTabbedPane1.setName("jTabbedPane1"); // NOI18N

    jDesktopPane1.setBackground(resourceMap.getColor("jDesktopPane1.background")); // NOI18N
    jDesktopPane1.setName("jDesktopPane1"); // NOI18N

    jFormattedTextField1.setText(resourceMap.getString("jFormattedTextField1.text")); // NOI18N
    jFormattedTextField1.setName("jFormattedTextField1"); // NOI18N
    jFormattedTextField1.setBounds(10, 120, 560, -1);
    jDesktopPane1.add(jFormattedTextField1, javax.swing.JLayeredPane.DEFAULT_LAYER);

    jFormattedTextField2.setText(resourceMap.getString("jFormattedTextField2.text")); // NOI18N
    jFormattedTextField2.setName("jFormattedTextField2"); // NOI18N
    jFormattedTextField2.setBounds(10, 40, 560, -1);
    jDesktopPane1.add(jFormattedTextField2, javax.swing.JLayeredPane.DEFAULT_LAYER);

    jTabbedPane1.addTab(resourceMap.getString("jDesktopPane1.TabConstraints.tabTitle"), jDesktopPane1); // NOI18N

    jDesktopPane2.setBackground(resourceMap.getColor("jDesktopPane2.background")); // NOI18N
    jDesktopPane2.setName("jDesktopPane2"); // NOI18N

    jScrollPane1.setName("jScrollPane1"); // NOI18N

    jTextArea1.setColumns(20);
    jTextArea1.setRows(5);
    jTextArea1.setName("jTextArea1"); // NOI18N
    jScrollPane1.setViewportView(jTextArea1);

    jScrollPane1.setBounds(10, 30, 760, 98);
    jDesktopPane2.add(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);

    jScrollPane2.setName("jScrollPane2"); // NOI18N

    jTextArea2.setColumns(20);
    jTextArea2.setRows(5);
    jTextArea2.setName("jTextArea2"); // NOI18N
    jScrollPane2.setViewportView(jTextArea2);

    jScrollPane2.setBounds(10, 160, 760, 97);
    jDesktopPane2.add(jScrollPane2, javax.swing.JLayeredPane.DEFAULT_LAYER);

    jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
    jButton1.setName("jButton1"); // NOI18N
    jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            tester(evt);
        }
    });
    jButton1.setBounds(610, 270, 93, 29);
    jDesktopPane2.add(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);

    jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
    jLabel1.setName("jLabel1"); // NOI18N
    jLabel1.setBounds(30, 140, 330, 16);
    jDesktopPane2.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

    jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
    jLabel2.setName("jLabel2"); // NOI18N
    jLabel2.setBounds(20, 10, 330, 16);
    jDesktopPane2.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

    jTabbedPane1.addTab(resourceMap.getString("jDesktopPane2.TabConstraints.tabTitle"), jDesktopPane2); // NOI18N

    org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
    mainPanel.setLayout(mainPanelLayout);
    mainPanelLayout.setHorizontalGroup(
        mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(org.jdesktop.layout.GroupLayout.TRAILING, jTabbedPane1)
    );
    mainPanelLayout.setVerticalGroup(
        mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(org.jdesktop.layout.GroupLayout.TRAILING, mainPanelLayout.createSequentialGroup()
            .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 375, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(36, Short.MAX_VALUE))
    );

    statusPanel.setName("statusPanel"); // NOI18N

    statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

    statusMessageLabel.setName("statusMessageLabel"); // NOI18N

    statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

    progressBar.setName("progressBar"); // NOI18N

    org.jdesktop.layout.GroupLayout statusPanelLayout = new org.jdesktop.layout.GroupLayout(statusPanel);
    statusPanel.setLayout(statusPanelLayout);
    statusPanelLayout.setHorizontalGroup(
        statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 798, Short.MAX_VALUE)
        .add(statusPanelLayout.createSequentialGroup()
            .addContainerGap()
            .add(statusMessageLabel)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 602, Short.MAX_VALUE)
            .add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(statusAnimationLabel)
            .addContainerGap())
    );
    statusPanelLayout.setVerticalGroup(
        statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(statusPanelLayout.createSequentialGroup()
            .add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(statusMessageLabel)
                .add(statusAnimationLabel)
                .add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(3, 3, 3))
    );

    menuBar.setName("menuBar"); // NOI18N

    fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
    fileMenu.setName("fileMenu"); // NOI18N

    openFileMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.META_MASK));
    openFileMenuItem.setText(resourceMap.getString("openFileMenuItem.text")); // NOI18N
    openFileMenuItem.setName("openFileMenuItem"); // NOI18N
    openFileMenuItem.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            openFileMenuItemMouseClicked(evt);
        }
    });
    fileMenu.add(openFileMenuItem);

    javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(bossconverter.BOSSConverterApp.class).getContext().getActionMap(BOSSConverterView.class, this);
    exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
    exitMenuItem.setName("exitMenuItem"); // NOI18N
    fileMenu.add(exitMenuItem);

    menuBar.add(fileMenu);

    helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
    helpMenu.setName("helpMenu"); // NOI18N

    aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
    aboutMenuItem.setName("aboutMenuItem"); // NOI18N
    helpMenu.add(aboutMenuItem);

    menuBar.add(helpMenu);

    mainFrame.setJMenuBar(menuBar);

    org.jdesktop.layout.GroupLayout mainFrameLayout = new org.jdesktop.layout.GroupLayout(mainFrame.getContentPane());
    mainFrame.getContentPane().setLayout(mainFrameLayout);
    mainFrameLayout.setHorizontalGroup(
        mainFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(0, 838, Short.MAX_VALUE)
        .add(mainFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainFrameLayout.createSequentialGroup()
                .addContainerGap()
                .add(mainPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap()))
        .add(mainFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainFrameLayout.createSequentialGroup()
                .addContainerGap()
                .add(statusPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap()))
    );
    mainFrameLayout.setVerticalGroup(
        mainFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(0, 531, Short.MAX_VALUE)
        .add(mainFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainFrameLayout.createSequentialGroup()
                .addContainerGap()
                .add(mainPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(100, Short.MAX_VALUE)))
        .add(mainFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainFrameLayout.createSequentialGroup()
                .add(474, 474, 474)
                .add(statusPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
    );

    setComponent(mainPanel);
    setMenuBar(menuBar);
    setStatusBar(statusPanel);
}// </editor-fold>

private void tester(java.awt.event.MouseEvent evt) {                        
        }                       

private void openFileMenuItemMouseClicked(java.awt.event.MouseEvent evt) {                                              

}                                             

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JDesktopPane jDesktopPane1;
private javax.swing.JDesktopPane jDesktopPane2;
private javax.swing.JForma开发者_开发百科ttedTextField jFormattedTextField1;
private javax.swing.JFormattedTextField jFormattedTextField2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextArea jTextArea2;
private javax.swing.JFrame mainFrame;
private javax.swing.JPanel mainPanel;
private javax.swing.JMenuBar menuBar;
private javax.swing.JMenuItem openFileMenuItem;
private javax.swing.JProgressBar progressBar;
private javax.swing.JLabel statusAnimationLabel;
private javax.swing.JLabel statusMessageLabel;
private javax.swing.JPanel statusPanel;
// End of variables declaration

private final Timer messageTimer;
private final Timer busyIconTimer;
private final Icon idleIcon;
private final Icon[] busyIcons = new Icon[15];
private int busyIconIndex = 0;

private JDialog aboutBox;
}

I apologize for the long code, I wasn't sure which part might be important to this case and which one is not.

If you know what is the problem here, please let me know


You have a mistake in your code; my simple self-contained test program shows that setResizable(false) works just fine:

package com.businesslink.core.tst.ld.dct;

import java.awt.*;
import javax.swing.*;

public class SwgTestFrame1b
extends JFrame
{

public SwgTestFrame1b() {
    super("SwgTestFrame1b");

    setBackground(Color.white);
    setResizable(false);
    pack();
    }

static public void main(String[] args) {
    new SwgTestFrame1b().show();
    }
}

A quick search of your code reveals nowhere that show or setVisible is invoked on mainFrame; it looks like you are only showing dialogs related to mainFrame. Now setResizable is only done on mainFrame, that will not impact any dialogs that are children of mainFrame. Nor will it affect the frame used by your FrameView.


PS, and just FTR, I absolutely abhor windows that are not resizable they are the mark of either an inadequate GUI toolkit or a lazy programmer.


The default application was not contained in a jFrame! It was in jPanel only which I didn't know how to make it none re-sizable. so I added a jFrame

you shouldn't be creating an extra JFrame, your panel was already in a frame You should have used something like this instead of creating a new frame:

getFrame().setResizeable(false);


fill code ((java.awt.Frame)root).setResizable(false); in application class, exactly in method configureWindow. (Application class is that class which instantiate View class. ) It should help

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜