Avatar billede axe2 Nybegynder
04. februar 2001 - 01:05 Der er 2 kommentarer og
1 løsning

panel placeringer

Hej jeg vil gerne have de to panel i denne JApplet til at blive siddende i øverste venstre hjørne. de finder tilsynladede altid midten, hvordan får jeg dem til at blive i øverste højre hjørne.

kode


/*
* GuitarScalerGui.java
*
* Created on 3. februar 2001, 23:49
*/


/**
*
* @author  lord x
* @version
*/
public class GuitarScalerGui extends javax.swing.JApplet {
   
    /** Creates new form GuitarScalerGui */
    public GuitarScalerGui() {
        setSize(400,800);
       
       
        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 FormEditor.
    */
    private void initComponents() {//GEN-BEGIN:initComponents
        jPanel1 = new javax.swing.JPanel();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox4 = new javax.swing.JCheckBox();
        jCheckBox5 = new javax.swing.JCheckBox();
        jCheckBox6 = new javax.swing.JCheckBox();
        jCheckBox7 = new javax.swing.JCheckBox();
        jCheckBox8 = new javax.swing.JCheckBox();
        jCheckBox9 = new javax.swing.JCheckBox();
        jCheckBox10 = new javax.swing.JCheckBox();
        jCheckBox11 = new javax.swing.JCheckBox();
        jCheckBox12 = new javax.swing.JCheckBox();
        jPanel2 = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        getContentPane().setLayout(new java.awt.GridBagLayout());
        java.awt.GridBagConstraints gridBagConstraints1;
       
        jPanel1.setLayout(new java.awt.GridBagLayout());
        java.awt.GridBagConstraints gridBagConstraints2;
        jPanel1.setBorder(new javax.swing.border.TitledBorder(\"Tone\"));
       
        jCheckBox2.setText(\"E\");
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
          gridBagConstraints2.ipadx = 11;
          gridBagConstraints2.insets = new java.awt.Insets(3, 12, 3, 9);
          gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST;
          jPanel1.add(jCheckBox2, gridBagConstraints2);
         
         
        jCheckBox3.setText(\"F\");
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.gridx = 0;
          gridBagConstraints2.gridy = 1;
          gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
          gridBagConstraints2.insets = new java.awt.Insets(3, 12, 3, 9);
          jPanel1.add(jCheckBox3, gridBagConstraints2);
         
         
        jCheckBox4.setText(\"F#\");
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.gridx = 0;
          gridBagConstraints2.gridy = 2;
          gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
          gridBagConstraints2.insets = new java.awt.Insets(3, 12, 3, 9);
          gridBagConstraints2.anchor = java.awt.GridBagConstraints.EAST;
          jPanel1.add(jCheckBox4, gridBagConstraints2);
         
         
        jCheckBox5.setText(\"G\");
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.gridx = 0;
          gridBagConstraints2.gridy = 3;
          gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
          gridBagConstraints2.insets = new java.awt.Insets(3, 12, 3, 9);
          jPanel1.add(jCheckBox5, gridBagConstraints2);
         
         
        jCheckBox6.setText(\"G#\");
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.gridx = 0;
          gridBagConstraints2.gridy = 4;
          gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
          gridBagConstraints2.insets = new java.awt.Insets(3, 12, 3, 9);
          jPanel1.add(jCheckBox6, gridBagConstraints2);
         
         
        jCheckBox7.setText(\"A\");
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.gridx = 0;
          gridBagConstraints2.gridy = 5;
          gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
          gridBagConstraints2.insets = new java.awt.Insets(3, 12, 3, 9);
          jPanel1.add(jCheckBox7, gridBagConstraints2);
         
         
        jCheckBox8.setText(\"Bb\");
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.gridx = 1;
          gridBagConstraints2.gridy = 0;
          jPanel1.add(jCheckBox8, gridBagConstraints2);
         
         
        jCheckBox9.setText(\"C\");
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.gridx = 1;
          gridBagConstraints2.gridy = 1;
          gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
          jPanel1.add(jCheckBox9, gridBagConstraints2);
         
         
        jCheckBox10.setText(\"C#\");
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.gridx = 1;
          gridBagConstraints2.gridy = 2;
          gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
          jPanel1.add(jCheckBox10, gridBagConstraints2);
         
         
        jCheckBox11.setText(\"D\");
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.gridx = 1;
          gridBagConstraints2.gridy = 3;
          gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
          jPanel1.add(jCheckBox11, gridBagConstraints2);
         
         
        jCheckBox12.setText(\"D#\");
          gridBagConstraints2 = new java.awt.GridBagConstraints();
          gridBagConstraints2.gridx = 1;
          gridBagConstraints2.gridy = 4;
          jPanel1.add(jCheckBox12, gridBagConstraints2);
         
         
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 0;
        gridBagConstraints1.gridy = 0;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTH;
        getContentPane().add(jPanel1, gridBagConstraints1);
       
       
        jPanel2.setLayout(new java.awt.GridBagLayout());
        java.awt.GridBagConstraints gridBagConstraints3;
        jPanel2.setBorder(new javax.swing.border.TitledBorder(\"Mode\"));
       
        jComboBox1.addItem(\"Scales\");
          jComboBox1.addItem(\"------\");
          jComboBox1.addItem(\"Major\");
          jComboBox1.addItem(\"Minor\");
          jComboBox1.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent evt) {
                  jComboBox1ActionPerformed(evt);
              }
          }
          );
          gridBagConstraints3 = new java.awt.GridBagConstraints();
          gridBagConstraints3.gridx = 0;
          gridBagConstraints3.gridy = 3;
          gridBagConstraints3.fill = java.awt.GridBagConstraints.BOTH;
          gridBagConstraints3.ipadx = 10;
          gridBagConstraints3.insets = new java.awt.Insets(6, 9, 8, 8);
          gridBagConstraints3.anchor = java.awt.GridBagConstraints.EAST;
          jPanel2.add(jComboBox1, gridBagConstraints3);
         
         
        jButton1.setText(\"jButton1\");
          gridBagConstraints3 = new java.awt.GridBagConstraints();
          gridBagConstraints3.fill = java.awt.GridBagConstraints.VERTICAL;
          gridBagConstraints3.ipadx = 1;
          gridBagConstraints3.insets = new java.awt.Insets(9, 9, 9, 11);
          jPanel2.add(jButton1, gridBagConstraints3);
         
         
        jTextField1.setText(\"jTextField1\");
          gridBagConstraints3 = new java.awt.GridBagConstraints();
          gridBagConstraints3.gridx = 0;
          gridBagConstraints3.gridy = 2;
          gridBagConstraints3.insets = new java.awt.Insets(4, 0, 6, 0);
          jPanel2.add(jTextField1, gridBagConstraints3);
         
         
        jLabel1.setText(\"Interval\");
          gridBagConstraints3 = new java.awt.GridBagConstraints();
          gridBagConstraints3.gridx = 0;
          gridBagConstraints3.gridy = 1;
          gridBagConstraints3.insets = new java.awt.Insets(3, 0, 3, 0);
          jPanel2.add(jLabel1, gridBagConstraints3);
         
         
        gridBagConstraints1 = new java.awt.GridBagConstraints();
        gridBagConstraints1.gridx = 4;
        gridBagConstraints1.gridy = 0;
        gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTH;
        getContentPane().add(jPanel2, gridBagConstraints1);
       
    }//GEN-END:initComponents

  private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
// Add your handling code here:
  }//GEN-LAST:event_jComboBox1ActionPerformed


  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JPanel jPanel1;
  private javax.swing.JCheckBox jCheckBox2;
  private javax.swing.JCheckBox jCheckBox3;
  private javax.swing.JCheckBox jCheckBox4;
  private javax.swing.JCheckBox jCheckBox5;
  private javax.swing.JCheckBox jCheckBox6;
  private javax.swing.JCheckBox jCheckBox7;
  private javax.swing.JCheckBox jCheckBox8;
  private javax.swing.JCheckBox jCheckBox9;
  private javax.swing.JCheckBox jCheckBox10;
  private javax.swing.JCheckBox jCheckBox11;
  private javax.swing.JCheckBox jCheckBox12;
  private javax.swing.JPanel jPanel2;
  private javax.swing.JComboBox jComboBox1;
  private javax.swing.JButton jButton1;
  private javax.swing.JTextField jTextField1;
  private javax.swing.JLabel jLabel1;
  // End of variables declaration//GEN-END:variables

}
Avatar billede stigc Nybegynder
04. februar 2001 - 01:08 #1
Hvis du sætter layout til ingen ting:

setLayout(null);

så kan du placere alle komponenter med 1 pixels nøjagtighed:


panel1.setBounds(0,0,200,200);


argumenter er følgennde:

setBounds(x,y,brede,højde);



Avatar billede axe2 Nybegynder
04. februar 2001 - 01:19 #2
ok gider du lave et eksempel, jeg må hellere forklare helt hvad der menes. Når man kører programmet og trækker vinduet ud så bliver de to paneler i midten istedet for at blive siddede i venste hjørne

Avatar billede creator Nybegynder
09. februar 2001 - 23:31 #3
Brug setLayout(new FlowLayout()); så bliver dine paneller oppe i venstre hjørne. Det der med at sætte panelerne på en x/y position, kan ikke anbefales, da f.eks. nogel Unix systemer og Mac positionerer anderleds end Microslot Windows. Derfor hold dig til layout managerne.
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester