Spostare etichetta e casella di testo a sinistra in GridBagLayout
-
12-10-2019 - |
Domanda
Può qualcuno di voi gente buona che mi aiuti, non riesco proprio a muoversi txtIPAddress ed etichetta indirizzo IP a sinistra, si è tagliata ora. Ho provato a sperimentare con weightx 0 a 1, ipadx ma non ha aiutato. Questa è la mia funzione di pannello rosso. Qualsiasi aiuto per favore?
pnlCom=new JPanel();
pnlCom.setBackground(Color.red);
pnlCom.setSize(460,160);
pnlCom.setLocation(10, 60);
add(pnlCom);
//add(pnlTcp);
add(pnlCommon);
GridBagLayout gb=new GridBagLayout();
GridBagConstraints gc=new GridBagConstraints();
pnlCom.setLayout(gb);
jLabelcommPort = setJLabel("Com Port : ");
jLabelbaudRate = setJLabel("Baud Rate : ");
jLabelplcAddress = setJLabel("Plc Address : ");
jLabelsendTime = setJLabel("<html>Send Time : <br/>x 50 ms (2 - 99)</html>");
jLabelx50 = setJLabel(" x 50 ms (2 - 99)");
jComboBoxcommPort = setJComboBox(commPortList);
jComboBoxbaudRate = setJComboBox(bitRateList);
jTextAreaPlcAddress = setJTextField("");
jTextAreaSendTime = setJTextField("");
lblComType=setJLabel("Com type : ");
cmbComType=setJComboBox(comType);
lblIPAddress=setJLabel("IP Address : ");
txtIPAddress=setJTextField("");
gc.insets = new Insets(10,0,0,0);
gc.ipadx = 80;
gc.weightx = 0.25;
gc.gridx = 0;
gc.gridy = 0;
gc.anchor=GridBagConstraints.EAST;
pnlCom.add(jLabelcommPort,gc);
gc.insets = new Insets(10,0,0,0);
gc.ipadx = 80;
gc.weightx = 0.25;
gc.gridx = 1;
gc.gridy = 0;
gc.anchor=GridBagConstraints.EAST;
pnlCom.add(jComboBoxcommPort,gc);
gc.insets=new Insets(10,0,0,0);
gc.ipadx=80;
gc.weightx = 0.5;
gc.gridx=0;
gc.gridy=1;
gc.anchor=GridBagConstraints.EAST;
pnlCom.add(jLabelbaudRate,gc);
gc.insets=new Insets(10,0,0,0);
gc.ipadx=80;
gc.weightx = 0.5;
gc.gridx=1;
gc.gridy=1;
gc.anchor=GridBagConstraints.EAST;
pnlCom.add(jComboBoxbaudRate,gc);
gc.insets=new Insets(10,0,0,0);
gc.ipadx=80;
gc.weightx = 0.5;
gc.gridx=0;
gc.gridy=2;
gc.anchor=GridBagConstraints.EAST;
pnlCom.add(lblComType,gc);
gc.insets=new Insets(10,0,0,0);
gc.ipadx=80;
gc.weightx = 0.25;
gc.gridx=1;
gc.gridy=2;
gc.anchor=GridBagConstraints.EAST;
pnlCom.add(cmbComType,gc);
gc.insets = new Insets(10,0,0,0);
gc.ipadx = 80;
gc.weightx = 0.25;
gc.gridx = 2;
gc.gridy = 0;
gc.anchor=GridBagConstraints.WEST;
pnlCom.add(lblIPAddress,gc);
gc.insets = new Insets(10,0,0,0);
gc.ipadx = 80;
gc.weightx = 0.25;
gc.gridx = 3;
gc.gridy = 0;
gc.anchor=GridBagConstraints.WEST;
pnlCom.add(txtIPAddress,gc);
Soluzione
Prova a impostare ipadx = 0 per tutti JLabels
. Una cosa è quello di ridurre tutti gli inserti. Hai lasciato inserto = 10 per tutti i controlli. Prova a impostare loro di 5.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow