私はパネルの内容をグラフィカルにデザインし、jframeで可能なすべてのメソッドをデザインし、別のフレームで他のフレームのインスタンスを作成してパネルを取得して影響を及ぼす必要がある別のjframeでそのパネルを使用します私の現在のjframeのパネル。ここ他のJframeの別のパネルからJframeのパネルコンテンツを設定するのが効果がないのはなぜですか?
は私が 私の設計されたパネルのモデルが含まれている最初のJFrameをしようとしたコードは次のとおりです。
私は最初のフレームを呼び出し、私はモデル化1にパネルを設定package chemsou;
import java.util.Hashtable;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
public class CheckListe extends javax.swing.JFrame {
/**
* Creates new form NewJFrame
*/
Hashtable<String, JCheckBox> model = new Hashtable<>();
public JPanel getPanel(){
return jPanel1;
}
public CheckListe(String[] list) {
initComponents();
jPanel1.setLayout(new java.awt.GridLayout(0, 1, 0, 4));
for (String element : list) {
model.put(element, new JCheckBox(element));
jPanel1.add(model.get(element));
}
}
public CheckListe() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new java.awt.GridLayout(0, 1, 0, 4));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 388, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(CheckListe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(CheckListe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(CheckListe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(CheckListe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CheckListe().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel jPanel1;
// End of variables declaration
}
私のJFrame:
private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String[] list =new String[]{"e1","e2","e3"};
CheckListe checkListe = new CheckListe(list);
// CheckListePanel.setLayout(checkListe.getPanel().getLayout());
CheckListePanel = checkListe.getPanel();
checkListe.setVisible(true);
CheckListePanel.setVisible(true);
CheckListePanel.setSize(100, 500);
CheckListePanel.revalidate();
CheckListePanel.repaint();
System.out.println("done");
}
私は他のJFrameが設計されたパネルが、発信者のJFrameは、どのようなI MS何
を行ういけない含まれていることを見ることができるコードを実行しますやりたい?
さて、私は混乱している:上記のクラスは/選択が行われたとき、このクラスの別のコンポーネント、JListのは、新しい選択を表示することができるようにクラスにPropertyChangeListenerを追加したJPanelは、使用しています。最初のフレームのプロパティを設定しようとしていますか?別のフレームでパネルを再利用しようとしていますか? – MadProgrammer
[複数のJFramesの使い方、良い/悪い練習]を参照してください(http://stackoverflow.com/q/9554636/418556) –
@HovercraftFullOfEels私が本当に欲しいのは、次のように言いましょう。あなたパネルこのフレームでデザインしたパネル。パネルは言う:私は自分自身を変身させ、私はあなたと同じようになり、あなたが望むパネルのように行動します。最終的に私のパネルには私がグラフィカルにデザインしたものがあることがわかります。どうやってするの?私はそれを見つけようとしています。 –