...それは下図のようなものを探して終わることです。これを試して、それがあなたが探しているものかどうかを見てください。私が思った
package quicktest;
public class ChaosLayout extends javax.swing.JPanel {
/**
* Creates new form ChaosLayout
*/
public ChaosLayout() {
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() {
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();
jButton1.setText("jButton1");
jButton2.setText("jButton2");
jButton3.setText("jButton3");
jButton4.setText("jButton4");
jButton5.setText("jButton5");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(55, 55, 55)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton5))
.addGap(18, 18, 18)
.addComponent(jButton4)
.addContainerGap(84, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton2)
.addComponent(jButton3)
.addComponent(jButton4))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 180, Short.MAX_VALUE)
.addComponent(jButton5)
.addContainerGap())
);
}// </editor-fold>
// Variables declaration - do not modify
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;
// End of variables declaration
}
賢明な変数名と同じレイアウト、と私はボタンにすべて同じ幅を作るために制約を追加しましたが、少し良く見えました。
package quicktest;
public class ChaosLayout extends javax.swing.JPanel {
/**
* Creates new form ChaosLayout
*/
public ChaosLayout() {
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() {
launch = new javax.swing.JButton();
chaos = new javax.swing.JButton();
trials = new javax.swing.JButton();
map = new javax.swing.JButton();
start = new javax.swing.JButton();
launch.setText("Launch");
chaos.setText("Chaos");
trials.setText("Trials");
map.setText("Map");
start.setText("Start");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(55, 55, 55)
.addComponent(trials)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(launch)
.addComponent(chaos)
.addComponent(start))
.addGap(18, 18, 18)
.addComponent(map)
.addContainerGap(99, Short.MAX_VALUE))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {chaos, launch, map, start, trials});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(launch)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(chaos)
.addComponent(trials)
.addComponent(map))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 180, Short.MAX_VALUE)
.addComponent(start)
.addContainerGap())
);
}// </editor-fold>
// Variables declaration - do not modify
private javax.swing.JButton chaos;
private javax.swing.JButton launch;
private javax.swing.JButton map;
private javax.swing.JButton start;
private javax.swing.JButton trials;
// End of variables declaration
}
GroupLayoutは、NetBeans IDEなどの自動レイアウトツールで使用するように設計されています。それ単独で使用するのはかなり難しいです。これをNetBeansでレイアウトできますか? – markspace
なぜ私はcouldnt、私はちょうど日食を使用していた参照してください。 – Brenton
Eclipseにレイアウト/ビルダーツールがある場合は、これも問題ありません。このようなレイアウトは、手作業で行うのは難しいことです。 – markspace