/* * Created by JFormDesigner on Wed Jul 01 15:38:49 MSK 2015 */ package monakhv.samlib.desk.gui; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; /** * @author Dmitry Monakhov */ public class AddTextValue extends JDialog { public interface CallBack{ void okClick(String answer); } private CallBack callBack; public AddTextValue(Frame owner,String label,String title, CallBack callBack ) { super(owner); initComponents(); label1.setText(label); setTitle(title); pack(); this.callBack=callBack; } public AddTextValue(JDialog owner,String label,String title, CallBack callBack,String text ) { super(owner); initComponents(); label1.setText(label); setTitle(title); pack(); this.callBack=callBack; textField1.setText(text); } private void cancelButtonActionPerformed(ActionEvent e) { this.setVisible(false); } private void okButtonActionPerformed(ActionEvent e) { String answer=textField1.getText(); callBack.okClick(answer); this.setVisible(false); } private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents dialogPane = new JPanel(); contentPanel = new JPanel(); label1 = new JLabel(); textField1 = new JTextField(); buttonBar = new JPanel(); okButton = new JButton(); cancelButton = new JButton(); //======== this ======== Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); //======== dialogPane ======== { dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12)); dialogPane.setLayout(new BorderLayout()); //======== contentPanel ======== { contentPanel.setLayout(new GridBagLayout()); ((GridBagLayout)contentPanel.getLayout()).columnWidths = new int[] {0, 150, 0}; ((GridBagLayout)contentPanel.getLayout()).rowHeights = new int[] {0, 0, 0, 0}; ((GridBagLayout)contentPanel.getLayout()).columnWeights = new double[] {0.0, 1.0, 1.0E-4}; ((GridBagLayout)contentPanel.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 1.0E-4}; //---- label1 ---- label1.setText("text"); contentPanel.add(label1, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0)); contentPanel.add(textField1, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 5, 0), 0, 0)); } dialogPane.add(contentPanel, BorderLayout.CENTER); //======== buttonBar ======== { buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0)); buttonBar.setLayout(new GridBagLayout()); ((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 85, 80}; ((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0, 0.0}; //---- okButton ---- okButton.setText("OK"); okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { okButtonActionPerformed(e); } }); buttonBar.add(okButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0)); //---- cancelButton ---- cancelButton.setText("Cancel"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cancelButtonActionPerformed(e); } }); buttonBar.add(cancelButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); } dialogPane.add(buttonBar, BorderLayout.SOUTH); } contentPane.add(dialogPane, BorderLayout.CENTER); pack(); setLocationRelativeTo(getOwner()); // JFormDesigner - End of component initialization //GEN-END:initComponents } // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables private JPanel dialogPane; private JPanel contentPanel; private JLabel label1; private JTextField textField1; private JPanel buttonBar; private JButton okButton; private JButton cancelButton; // JFormDesigner - End of variables declaration //GEN-END:variables }