Java JFrame未重新验证
我的JPanel没有调整到窗口的大小,我至少希望它在调整大小时移到中心,JTextArea做得很好,但我不能让带有按钮的JPanel也调整大小。这是我的密码:Java JFrame未重新验证,java,swing,resize,jframe,jpanel,Java,Swing,Resize,Jframe,Jpanel,我的JPanel没有调整到窗口的大小,我至少希望它在调整大小时移到中心,JTextArea做得很好,但我不能让带有按钮的JPanel也调整大小。这是我的密码: /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in t
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package privatelessontracknetbeans;
import java.awt.BorderLayout;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
/**
*
* @author Brent C
*/
public class PrivateLessonsTrackerGUI extends javax.swing.JFrame {
/**
* Creates new form PrivateLessonsTrackerGUI
*/
public PrivateLessonsTrackerGUI() {
initComponents();
}
/**
* 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() {
jPanel1 = new javax.swing.JPanel();
sun = new javax.swing.JButton();
mon = new javax.swing.JButton();
tue = new javax.swing.JButton();
wed = new javax.swing.JButton();
thu = new javax.swing.JButton();
fri = new javax.swing.JButton();
sat = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem3 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
addInstructors = new javax.swing.JMenuItem();
jMenu3 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Private Lessons Tracker");
jPanel1.addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentResized(java.awt.event.ComponentEvent evt) {
jPanel1ComponentResized(evt);
}
});
sun.setText("Sun");
sun.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sunActionPerformed(evt);
}
});
mon.setText("Mon");
mon.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
monActionPerformed(evt);
}
});
tue.setText("Tue");
tue.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
tueActionPerformed(evt);
}
});
wed.setText("Wed");
wed.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
wedActionPerformed(evt);
}
});
thu.setText("Thu");
thu.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
thuActionPerformed(evt);
}
});
fri.setText("Fri");
fri.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
friActionPerformed(evt);
}
});
sat.setText("Sat");
sat.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
satActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(sun, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(mon, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tue)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(wed)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(thu)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(fri)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(sat)
.addContainerGap(29, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(sun)
.addComponent(mon)
.addComponent(tue)
.addComponent(wed)
.addComponent(thu)
.addComponent(fri)
.addComponent(sat))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jTextArea1.setEditable(false);
jTextArea1.setColumns(20);
jTextArea1.setLineWrap(true);
jTextArea1.setRows(5);
jTextArea1.setWrapStyleWord(true);
jScrollPane1.setViewportView(jTextArea1);
jMenu1.setText("File");
jMenuItem3.setText("Home");
jMenu1.add(jMenuItem3);
jMenuItem2.setText("Exit");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem2);
jMenuBar1.add(jMenu1);
jMenu2.setText("Instructor");
addInstructors.setText("Add Instructor(s)");
addInstructors.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addInstructorsActionPerformed(evt);
}
});
jMenu2.add(addInstructors);
jMenuBar1.add(jMenu2);
jMenu3.setText("Student");
jMenuBar1.add(jMenu3);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1))
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
.addContainerGap())
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>
private void addInstructorsActionPerformed(java.awt.event.ActionEvent evt) {
AddingInstructorsGUI aiGUI = new AddingInstructorsGUI();
aiGUI.setVisible(true);
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void sunActionPerformed(java.awt.event.ActionEvent evt) {
jTextArea1 = new JTextArea("Sundays List");
jTextArea1.setEditable(false);
jTextArea1.setColumns(20);
jTextArea1.setLineWrap(true);
jTextArea1.setRows(5);
jTextArea1.setWrapStyleWord(true);
jScrollPane1.setViewportView(jTextArea1);
}
private void monActionPerformed(java.awt.event.ActionEvent evt) {
jTextArea1 = new JTextArea("Mondays List");
jTextArea1.setEditable(false);
jTextArea1.setColumns(20);
jTextArea1.setLineWrap(true);
jTextArea1.setRows(5);
jTextArea1.setWrapStyleWord(true);
jScrollPane1.setViewportView(jTextArea1);
}
private void tueActionPerformed(java.awt.event.ActionEvent evt) {
jTextArea1 = new JTextArea("Tuesdays List");
jTextArea1.setEditable(false);
jTextArea1.setColumns(20);
jTextArea1.setLineWrap(true);
jTextArea1.setRows(5);
jTextArea1.setWrapStyleWord(true);
jScrollPane1.setViewportView(jTextArea1);
}
private void wedActionPerformed(java.awt.event.ActionEvent evt) {
jTextArea1 = new JTextArea("Wednesdays List");
jTextArea1.setEditable(false);
jTextArea1.setColumns(20);
jTextArea1.setLineWrap(true);
jTextArea1.setRows(5);
jTextArea1.setWrapStyleWord(true);
jScrollPane1.setViewportView(jTextArea1);
}
private void thuActionPerformed(java.awt.event.ActionEvent evt) {
jTextArea1 = new JTextArea("Thursdays List");
jTextArea1.setEditable(false);
jTextArea1.setColumns(20);
jTextArea1.setLineWrap(true);
jTextArea1.setRows(5);
jTextArea1.setWrapStyleWord(true);
jScrollPane1.setViewportView(jTextArea1);
}
private void friActionPerformed(java.awt.event.ActionEvent evt) {
jTextArea1 = new JTextArea("Fridays List");
jTextArea1.setEditable(false);
jTextArea1.setColumns(20);
jTextArea1.setLineWrap(true);
jTextArea1.setRows(5);
jTextArea1.setWrapStyleWord(true);
jScrollPane1.setViewportView(jTextArea1);
}
private void satActionPerformed(java.awt.event.ActionEvent evt) {
jTextArea1 = new JTextArea("Saturdays List");
jTextArea1.setEditable(false);
jTextArea1.setColumns(20);
jTextArea1.setLineWrap(true);
jTextArea1.setRows(5);
jTextArea1.setWrapStyleWord(true);
jScrollPane1.setViewportView(jTextArea1);
}
private void jPanel1ComponentResized(java.awt.event.ComponentEvent evt) {
this.jPanel1.revalidate();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new PrivateLessonsTrackerGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JMenuItem addInstructors;
private javax.swing.JButton fri;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JButton mon;
private javax.swing.JButton sat;
private javax.swing.JButton sun;
private javax.swing.JButton thu;
private javax.swing.JButton tue;
private javax.swing.JButton wed;
// End of variables declaration
/*
*要更改此许可证标题,请在“项目属性”中选择“许可证标题”。
*要更改此模板文件,请选择工具|模板
*然后在编辑器中打开模板。
*/
包privatelessontracknetbeans;
导入java.awt.BorderLayout;
导入javax.swing.JTextArea;
导入javax.swing.SwingUtilities;
/**
*
*@作者布伦特C
*/
公共类PrivateLessonsTrackerGUI扩展了javax.swing.JFrame{
/**
*创建新表单PrivatelessOnTrackerGUI
*/
公共-私人TrackerGui(){
初始化组件();
}
/**
*从构造函数中调用此方法来初始化表单。
*警告:不要修改此代码。此方法的内容始终为
*由表单编辑器重新生成。
*/
@抑制警告(“未选中”)
//
私有组件(){
jPanel1=newjavax.swing.JPanel();
sun=newjavax.swing.JButton();
mon=newjavax.swing.JButton();
tue=newjavax.swing.JButton();
wed=newjavax.swing.JButton();
thu=newjavax.swing.JButton();
fri=newjavax.swing.JButton();
sat=newjavax.swing.JButton();
jScrollPane1=newjavax.swing.JScrollPane();
jTextArea1=newjavax.swing.JTextArea();
jMenuBar1=newjavax.swing.JMenuBar();
jMenu1=newjavax.swing.JMenu();
jMenuItem3=newjavax.swing.JMenuItem();
jMenuItem2=newjavax.swing.JMenuItem();
jMenu2=newjavax.swing.JMenu();
addInstructors=new javax.swing.JMenuItem();
jMenu3=newjavax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle(“私人课程跟踪器”);
addComponentListener(新java.awt.event.ComponentAdapter(){
public void ComponentResistized(java.awt.event.ComponentEvent evt){
JPANEL1元件电阻化(evt);
}
});
sun.setText(“sun”);
addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行的操作(evt);
}
});
mon.setText(“mon”);
mon.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行单操作(evt);
}
});
星期二(星期二);
tue.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
tueActionPerformed(evt);
}
});
wed.setText(“wed”);
addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行的操作(evt);
}
});
thu.setText(“thu”);
thu.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行的操作(evt);
}
});
fri.setText(“fri”);
addActionListener(新的java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行摩擦试验(evt);
}
});
sat.setText(“sat”);
sat.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
已执行的任务(evt);
}
});
javax.swing.GroupLayout jPanel1Layout=新的javax.swing.GroupLayout(jPanel1);
setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jpanellayout.createSequentialGroup()
.addContainerGap()
.addComponent(sun,javax.swing.GroupLayout.PREFERRED\u SIZE,62,javax.swing.GroupLayout.PREFERRED\u SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(mon,javax.swing.GroupLayout.PREFERRED\u SIZE,61,javax.swing.GroupLayout.PREFERRED\u SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(星期二)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(星期三)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(thu)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(星期五)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(sat)
.addContainerGap(29,简称最大值))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jpanellayout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(sun)
.addComponent(周一)
.addComponent(星期二)
.addComponent(星期三)
.addComponent(thu)
.addComponent(星期五)
.addComponent(sat))
.addContainerGap(javax.swing.GroupLayout.DEFAULT\u SIZE,Short.MAX\u VALUE))
);
jTextArea1.setEditable(假);
jTextArea1.设置列(20);
jTextArea1.setLineWrap(真);
jTextArea1.设置行(5);
jTextArea1.setWrapStyleWord(true);
jScrollPane1.setViewportView(jTextArea1);
setText(“文件”);
jMenuItem3.setText(“主页”);
jMenu1.add(jMenuItem3);
jMenuItem2.setText(“退出”);
jMenuItem2.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
jMenuItem2ActionPerformed(evt);
jPanel1.setLayout(new FlowLayout(FlowLayout.CENTER));