El Frame principal debería ser mainPanel... de todas formas, no tengo ni idea porque, como ya he dicho, usando el asistente de NetBeans se genera mucho código (como el de todos los botones).
De hecho, del código de 461 líneas que tengo, yo lo único que he hecho es el método redimensionar... y no funciona asiq vamos bien.
Aún así, aunque use mainPanel.setSize(x, y) o mainPanel.getParent().setSize(x, y) sigue sin funcionar...
Esto es lo que NetBeans ha generado el solito:
De hecho, del código de 461 líneas que tengo, yo lo único que he hecho es el método redimensionar... y no funciona asiq vamos bien.
Aún así, aunque use mainPanel.setSize(x, y) o mainPanel.getParent().setSize(x, y) sigue sin funcionar...
Esto es lo que NetBeans ha generado el solito:
Código (java) [Seleccionar]
/*
* CalculadoraCasaView.java
*/
package calculadoracasa;
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;
import javax.swing.JPanel;
/**
* The application's main frame.
*/
public class CalculadoraCasaView extends FrameView {
public CalculadoraCasaView(SingleFrameApplication app) {
super(app);
initComponents();
redimensionar(235, 280);
// status bar initialization - message timeout, idle icon and busy animation, etc
ResourceMap resourceMap = getResourceMap();
int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
messageTimer = new Timer(messageTimeout, new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
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;
}
});
// 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()) {
busyIconIndex = 0;
busyIconTimer.start();
}
} else if ("done".equals(propertyName)) {
busyIconTimer.stop();
} else if ("message".equals(propertyName)) {
String text = (String)(evt.getNewValue());
messageTimer.restart();
} else if ("progress".equals(propertyName)) {
int value = (Integer)(evt.getNewValue());
}
}
});
}
@Action
public void showAboutBox() {
if (aboutBox == null) {
JFrame mainFrame = CalculadoraCasaApp.getApplication().getMainFrame();
aboutBox = new CalculadoraCasaAboutBox(mainFrame);
aboutBox.setLocationRelativeTo(mainFrame);
}
CalculadoraCasaApp.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() {
mainPanel = new javax.swing.JPanel();
jtxtPantalla = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jButton5 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton7 = new javax.swing.JButton();
jButton8 = new javax.swing.JButton();
jButton9 = new javax.swing.JButton();
jButton0 = new javax.swing.JButton();
jButtonComa = new javax.swing.JButton();
jButtonDividir = new javax.swing.JButton();
jButtonMultiplicar = new javax.swing.JButton();
jButtonRestar = new javax.swing.JButton();
jButtonSumar = new javax.swing.JButton();
jButtonC = new javax.swing.JButton();
jButtonM = new javax.swing.JButton();
jButtonMMas = new javax.swing.JButton();
jButtonMR = new javax.swing.JButton();
jButtonMC = new javax.swing.JButton();
jButtonIgual = new javax.swing.JButton();
opRadian = new javax.swing.JRadioButton();
opGrados = new javax.swing.JRadioButton();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jButtonExp = new javax.swing.JButton();
jButtonSeno = new javax.swing.JButton();
jButtonCoseno = new javax.swing.JButton();
jButtonTangente = new javax.swing.JButton();
jButtonLogaritmo = new javax.swing.JButton();
jButtonLogN = new javax.swing.JButton();
buttonGroupGrados = new javax.swing.ButtonGroup();
buttonGroupTipo = new javax.swing.ButtonGroup();
mainPanel.setName("mainPanel"); // NOI18N
mainPanel.setPreferredSize(new java.awt.Dimension(235, 280));
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(calculadoracasa.CalculadoraCasaApp.class).getContext().getResourceMap(CalculadoraCasaView.class);
jtxtPantalla.setBackground(resourceMap.getColor("jtxtPantalla.background")); // NOI18N
jtxtPantalla.setEditable(false);
jtxtPantalla.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
jtxtPantalla.setText(resourceMap.getString("jtxtPantalla.text")); // NOI18N
jtxtPantalla.setName("jtxtPantalla"); // NOI18N
jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
jButton1.setName("jButton1"); // NOI18N
jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
jButton2.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jButton2.setName("jButton2"); // NOI18N
jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
jButton3.setName("jButton3"); // NOI18N
jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
jButton4.setName("jButton4"); // NOI18N
jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
jButton5.setName("jButton5"); // NOI18N
jButton6.setText(resourceMap.getString("jButton6.text")); // NOI18N
jButton6.setName("jButton6"); // NOI18N
jButton7.setText(resourceMap.getString("jButton7.text")); // NOI18N
jButton7.setName("jButton7"); // NOI18N
jButton8.setText(resourceMap.getString("jButton8.text")); // NOI18N
jButton8.setName("jButton8"); // NOI18N
jButton9.setText(resourceMap.getString("jButton9.text")); // NOI18N
jButton9.setName("jButton9"); // NOI18N
jButton0.setText(resourceMap.getString("jButton0.text")); // NOI18N
jButton0.setName("jButton0"); // NOI18N
jButtonComa.setText(resourceMap.getString("jButtonComa.text")); // NOI18N
jButtonComa.setName("jButtonComa"); // NOI18N
jButtonDividir.setText(resourceMap.getString("jButtonDividir.text")); // NOI18N
jButtonDividir.setName("jButtonDividir"); // NOI18N
jButtonMultiplicar.setText(resourceMap.getString("jButtonMultiplicar.text")); // NOI18N
jButtonMultiplicar.setName("jButtonMultiplicar"); // NOI18N
jButtonRestar.setText(resourceMap.getString("jButtonRestar.text")); // NOI18N
jButtonRestar.setName("jButtonRestar"); // NOI18N
jButtonSumar.setText(resourceMap.getString("jButtonSumar.text")); // NOI18N
jButtonSumar.setName("jButtonSumar"); // NOI18N
jButtonC.setText(resourceMap.getString("jButtonC.text")); // NOI18N
jButtonC.setName("jButtonC"); // NOI18N
jButtonC.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButtonCMouseClicked(evt);
}
});
jButtonM.setText(resourceMap.getString("jButtonM.text")); // NOI18N
jButtonM.setName("jButtonM"); // NOI18N
jButtonMMas.setText(resourceMap.getString("jButtonMMas.text")); // NOI18N
jButtonMMas.setName("jButtonMMas"); // NOI18N
jButtonMR.setText(resourceMap.getString("jButtonMR.text")); // NOI18N
jButtonMR.setName("jButtonMR"); // NOI18N
jButtonMC.setText(resourceMap.getString("jButtonMC.text")); // NOI18N
jButtonMC.setName("jButtonMC"); // NOI18N
jButtonIgual.setText(resourceMap.getString("jButtonIgual.text")); // NOI18N
jButtonIgual.setName("jButtonIgual"); // NOI18N
buttonGroupGrados.add(opRadian);
opRadian.setText(resourceMap.getString("opRadian.text")); // NOI18N
opRadian.setName("opRadian"); // NOI18N
opRadian.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
opRadianActionPerformed(evt);
}
});
buttonGroupGrados.add(opGrados);
opGrados.setSelected(true);
opGrados.setText(resourceMap.getString("opGrados.text")); // NOI18N
opGrados.setName("opGrados"); // NOI18N
buttonGroupTipo.add(jRadioButton1);
jRadioButton1.setSelected(true);
jRadioButton1.setText(resourceMap.getString("jRadioButton1.text")); // NOI18N
jRadioButton1.setName("jRadioButton1"); // NOI18N
jRadioButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jRadioButton1MouseClicked(evt);
}
});
buttonGroupTipo.add(jRadioButton2);
jRadioButton2.setText(resourceMap.getString("jRadioButton2.text")); // NOI18N
jRadioButton2.setName("jRadioButton2"); // NOI18N
jRadioButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jRadioButton2MouseClicked(evt);
}
});
jButtonExp.setText(resourceMap.getString("jButtonExp.text")); // NOI18N
jButtonExp.setName("jButtonExp"); // NOI18N
jButtonSeno.setText(resourceMap.getString("jButtonSeno.text")); // NOI18N
jButtonSeno.setName("jButtonSeno"); // NOI18N
jButtonCoseno.setText(resourceMap.getString("jButtonCoseno.text")); // NOI18N
jButtonCoseno.setName("jButtonCoseno"); // NOI18N
jButtonTangente.setText(resourceMap.getString("jButtonTangente.text")); // NOI18N
jButtonTangente.setName("jButtonTangente"); // NOI18N
jButtonLogaritmo.setText(resourceMap.getString("jButtonLogaritmo.text")); // NOI18N
jButtonLogaritmo.setName("jButtonLogaritmo"); // NOI18N
jButtonLogN.setText(resourceMap.getString("jButtonLogN.text")); // NOI18N
jButtonLogN.setName("jButtonLogN"); // NOI18N
javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
mainPanel.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(mainPanelLayout.createSequentialGroup()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(opGrados)
.addGap(28, 28, 28))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(opRadian)
.addGap(18, 18, 18)))
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton2)
.addComponent(jRadioButton1)))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jButton7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jButton0, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
.addComponent(jButton8, javax.swing.GroupLayout.Alignment.LEADING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButtonComa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton9))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButtonDividir, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)
.addComponent(jButtonMultiplicar, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE)))
.addGroup(mainPanelLayout.createSequentialGroup()
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButtonSumar, javax.swing.GroupLayout.DEFAULT_SIZE, 41, Short.MAX_VALUE))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jButton5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButtonRestar, javax.swing.GroupLayout.DEFAULT_SIZE, 39, Short.MAX_VALUE))))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jButtonC)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButtonIgual, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(mainPanelLayout.createSequentialGroup()
.addComponent(jButtonM)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButtonMMas)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButtonMR)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButtonMC))
.addComponent(jtxtPantalla))
.addGap(37, 37, 37)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButtonLogN, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButtonLogaritmo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButtonTangente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButtonCoseno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButtonSeno, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButtonExp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
mainPanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton0, jButton1, jButton2, jButton3, jButton4, jButton5, jButton6, jButton7, jButton8, jButton9, jButtonC, jButtonComa, jButtonDividir, jButtonM, jButtonMC, jButtonMMas, jButtonMR, jButtonMultiplicar, jButtonRestar, jButtonSumar});
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jtxtPantalla, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jRadioButton1)
.addComponent(opGrados))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jRadioButton2)
.addComponent(opRadian))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3)
.addComponent(jButtonSumar)
.addComponent(jButtonExp))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton4)
.addComponent(jButton5)
.addComponent(jButton6)
.addComponent(jButtonRestar)
.addComponent(jButtonSeno))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton7)
.addComponent(jButton8)
.addComponent(jButton9)
.addComponent(jButtonMultiplicar)
.addComponent(jButtonCoseno))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton0)
.addComponent(jButtonComa)
.addComponent(jButtonDividir)
.addComponent(jButtonTangente))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButtonC)
.addComponent(jButtonIgual)
.addComponent(jButtonLogaritmo))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButtonM)
.addComponent(jButtonMMas)
.addComponent(jButtonMR)
.addComponent(jButtonMC)
.addComponent(jButtonLogN))
.addContainerGap(13, Short.MAX_VALUE))
);
mainPanelLayout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {jButton0, jButton1, jButton2, jButton3, jButton4, jButton5, jButton6, jButton7, jButton8, jButton9, jButtonC, jButtonComa, jButtonDividir, jButtonM, jButtonMC, jButtonMMas, jButtonMR, jButtonMultiplicar, jButtonRestar, jButtonSumar});
setComponent(mainPanel);
}// </editor-fold>
private void opRadianActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButtonCMouseClicked(java.awt.event.MouseEvent evt) {
jtxtPantalla.setText("");
}
private void jRadioButton1MouseClicked(java.awt.event.MouseEvent evt) {
redimensionar(235, 280);
}
private void jRadioButton2MouseClicked(java.awt.event.MouseEvent evt) {
redimensionar(325, 280);
}
// Variables declaration - do not modify
private javax.swing.ButtonGroup buttonGroupGrados;
private javax.swing.ButtonGroup buttonGroupTipo;
private javax.swing.JButton jButton0;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JButton jButton8;
private javax.swing.JButton jButton9;
private javax.swing.JButton jButtonC;
private javax.swing.JButton jButtonComa;
private javax.swing.JButton jButtonCoseno;
private javax.swing.JButton jButtonDividir;
private javax.swing.JButton jButtonExp;
private javax.swing.JButton jButtonIgual;
private javax.swing.JButton jButtonLogN;
private javax.swing.JButton jButtonLogaritmo;
private javax.swing.JButton jButtonM;
private javax.swing.JButton jButtonMC;
private javax.swing.JButton jButtonMMas;
private javax.swing.JButton jButtonMR;
private javax.swing.JButton jButtonMultiplicar;
private javax.swing.JButton jButtonRestar;
private javax.swing.JButton jButtonSeno;
private javax.swing.JButton jButtonSumar;
private javax.swing.JButton jButtonTangente;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JTextField jtxtPantalla;
private javax.swing.JPanel mainPanel;
private javax.swing.JRadioButton opGrados;
private javax.swing.JRadioButton opRadian;
// End of variables declaration
double num1=0, num2=0, memoria=0;
boolean igualPulsado=false, opPulsado=false;
int op;
void redimensionar(int x, int y){
mainPanel.setSize(x, y);
}
private final Timer messageTimer;
private final Timer busyIconTimer;
private final Icon[] busyIcons = new Icon[15];
private int busyIconIndex = 0;
private JDialog aboutBox;
}