che il mio nuovo modo di gestire questo problema:
public static void showForms(JFrame frame,JPanel[] jPanels){
for (JPanel jPanel : jPanels) {
showForms(frame, jPanel,false);
}
int extendedState = frame.getExtendedState();
if (extendedState==JFrame.MAXIMIZED_BOTH) {
return;
}
frame.pack();
}
public static void showForms(JFrame frame, JPanel jPanel, boolean doPack) {
jPanel.setVisible(true);
if (doPack) {
int extendedState = frame.getExtendedState();
if (extendedState==JFrame.MAXIMIZED_BOTH) {
return;
}
frame.pack();
}
}
public static void hideForms(JFrame frame, JPanel[] jPanel) {
for (JPanel panel : jPanel) {
hideForms(frame, panel, false);
}
int extendedState = frame.getExtendedState();
if (extendedState==JFrame.MAXIMIZED_BOTH) {
return;
}
frame.pack();
}
public static void hideForms(JFrame frame, JPanel jPanel, boolean doPack) {
jPanel.setVisible(false);
if (doPack) {
int extendedState = frame.getExtendedState();
if (extendedState==JFrame.MAXIMIZED_BOTH) {
return;
}
frame.pack();
}
}
I m utilizzando questi metodi per nascondere e mostrare jpanels sul mio JFrame.
campione su un codice del pulsante
JFrameTools.showForms(this,searchPanel,false);
JFrameTools.showForms(this,insertingPanel,true);
JFrameTools.showForms(this,new jPanel[]{insertingPanel,searchPanel,printingPanel});
lo stesso per il nascondiglio.
fonte
2017-02-28 23:19:55
Ridimensiona fotogramma dopo l'esecuzione di pack(), solo un pensiero! Per ridimensionamento intendo programmaticamente – doNotCheckMyBlog