Question: How can I use Window Builder in Java so that, depending on the number of edges a node has, text fields are added to input

How can I use Window Builder in Java so that, depending on the number of edges a node has, text fields are added to input edge data, which include weight and time -in minutes-? I'm trying to create a route management system in Java using an undirected graph via an adjacency list. However, my question focuses on the visual aspect.package visual;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.awt.Toolkit;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTextField;
public class Aadir extends JDialog {
private final JPanel contentPanel = new JPanel();
private JTextField textFieldId;
private JTextField textFieldCantA;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
/**
* Launch the application.
*/
public static void main(String[] args){
try {
Aadir dialog = new Aadir();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e){
e.printStackTrace();
}
}
/**
* Create the dialog.
*/
public Aadir(){
setTitle("A\u00F1adir Ubicaci\u00F3n");
setIconImage(Toolkit.getDefaultToolkit().getImage(Aadir.class.getResource("/imagenes/imgpri2.jpg")));
setBackground(new Color(255,255,255));
setBounds(100,100,450,300);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBackground(new Color(255,255,255));
contentPanel.setBorder(new EmptyBorder(5,5,5,5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(new BorderLayout(0,0));
setLocationRelativeTo(null);
{
JPanel panel = new JPanel();
panel.setForeground(new Color(0,204,204));
contentPanel.add(panel, BorderLayout.CENTER);
panel.setLayout(null);
JLabel lblID = new JLabel("ID:");
lblID.setForeground(new Color(0,204,204));
lblID.setFont(new Font("Segoe UI Black", Font.PLAIN, 13));
lblID.setBounds(12,25,56,16);
panel.add(lblID);
JLabel lblVertice = new JLabel("Vertice (nombre):");
lblVertice.setForeground(new Color(0,204,204));
lblVertice.setFont(new Font("Segoe UI Black", Font.PLAIN, 13));
lblVertice.setBounds(214,25,138,16);
panel.add(lblVertice);
JLabel lblcantLugar = new JLabel("Cantidad de aristas: ");
lblcantLugar.setForeground(new Color(0,204,204));
lblcantLugar.setFont(new Font("Segoe UI Black", Font.PLAIN, 13));
lblcantLugar.setBounds(12,91,138,16);
panel.add(lblcantLugar);
textFieldId = new JTextField();
textFieldId.setBounds(39,22,116,22);
panel.add(textFieldId);
textFieldId.setColumns(10);
textFieldCantA = new JTextField();
textFieldCantA.setColumns(10);
textFieldCantA.setBounds(151,88,50,22);
panel.add(textFieldCantA);
textField = new JTextField();
textField.setColumns(10);
textField.setBounds(340,22,70,22);
panel.add(textField);
JLabel lblPeso = new JLabel("Peso:");
lblPeso.setForeground(new Color(0,204,204));
lblPeso.setFont(new Font("Segoe UI Black", Font.PLAIN, 13));
lblPeso.setBounds(214,91,138,16);
panel.add(lblPeso);
JLabel lblTiempomin = new JLabel("Tiempo(min)");
lblTiempomin.setForeground(new Color(0,204,204));
lblTiempomin.setFont(new Font("Segoe UI Black", Font.PLAIN, 13));
lblTiempomin.setBounds(12,151,138,16);
panel.add(lblTiempomin);
textField_1= new JTextField();
textField_1.setColumns(10);
textField_1.setBounds(151,148,50,22);
panel.add(textField_1);
textField_2= new JTextField();
textField_2.setColumns(10);
textField_2.setBounds(340,88,70,22);
panel.add(textField_2);
}
{
JPanel buttonPane = new JPanel();
buttonPane.setBackground(new Color(216,191,216));
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
okButton.setBackground(new Color(255,255,255));
okButton.setForeground(new Color(186,85,211));
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.setBackground(new Color(255,255,255));
cancelButton.setForeground(new Color(218,112,214));
cancelButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dispose();
}
});
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
}
}
How can I use Window Builder in Java so that,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!