Trouble with JDialog


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Trouble with JDialog

  1. #1
    Join Date
    Nov 2003
    Posts
    2

    Trouble with JDialog

    Hi,

    This is my first post here.

    I am launching a dialog from a button (just calling launch in the code below) however the dialog does not show it self correctly. The this.pack() does not seem to be working as the button panel is not displayed, it is hidden until I manually resize the JDialog.

    I was hoping somebody could help with this. Is there anyway I can get the dialog to show fully and exactly what has been added to it all horizontally across al a FlowLayout and not move anything onto the next line and out of sight?

    Thanks in advance, L.


    Here is the code:

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    import java.awt.Color;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionListener;

    import javax.swing.*;

    import uk.co.futureroute.discovery.projectguibridge.*;

    public class AddPredicateDialog extends JDialog{
    PredicatePanelView predPanelView = null;
    // Table model used
    PredicateTableModel typeContentModel = null;
    //JPanels used
    JPanel addPredDisplayPanel = null;
    JPanel containerPanel = null;
    JPanel buttonPanel = null;
    // JLabels
    JLabel addPredNameLabel = new JLabel("");
    JLabel dialogCloseBracketLabel = new JLabel(")");
    // JComboBox
    JComboBox listTypesComBox = new JComboBox();
    // JButtons used
    JButton okButton = new JButton("OK");
    JButton cancelButton = new JButton("Cancel");

    private boolean forEdit;



    public AddPredicateDialog(ActionListener actList, PredicatePanelView predPanelView){
    this.predPanelView = predPanelView;
    init();
    this.okButton.addActionListener(actList);
    }


    public void init(){

    typeContentModel = predPanelView.projGuiBridge.getTypesTableModel();
    addPredDisplayPanel = new JPanel();
    buttonPanel = new JPanel();
    containerPanel = new JPanel();
    this.setContentPane(containerPanel);
    this.setTitle("Predicate");
    this.pack();
    this.validate();
    }



    public void launch(int noOfComboBoxes){
    containerPanel.removeAll();
    containerPanel.setLayout(new GridLayout());
    addPredDisplayPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10));
    addPredDisplayPanel.removeAll();
    addPredDisplayPanel.add(addPredNameLabel);
    //dialogComboBoxList.clear();
    for(int i = 0; i < noOfComboBoxes; i++){
    if(i != 0){
    addPredDisplayPanel.add(new JLabel(","));
    }
    JComboBox dialogArgsComboBox = new JComboBox();
    dialogArgsComboBox.setBackground(Color.WHITE);
    for(int c = 0; c < typeContentModel.getRowCount(); c++){
    String type = typeContentModel.getValueAt(c, 0).toString();
    dialogArgsComboBox.addItem(type);
    }
    addPredDisplayPanel.add(dialogArgsComboBox);
    }
    addPredDisplayPanel.add(dialogCloseBracketLabel);
    buttonPanel.setLayout(new GridLayout(2, 1));
    buttonPanel.add(okButton);
    buttonPanel.add(cancelButton);
    addPredDisplayPanel.add(buttonPanel);
    containerPanel.add(addPredDisplayPanel);

    this.setVisible(true);
    }



    public void launch(Object[] selected){

    this.setVisible(true);
    }


    public void removeDialog(){
    this.setVisible(false);

    }


    public boolean wasForEdit() {
    return this.forEdit;
    }



    }

  2. #2
    Join Date
    Nov 2003
    Posts
    2
    Hi I have made a change which makes it a little bit better, but the combo boxes are going onto the second line now.

    The thing is if I kill the dialog and relaunch it, it opens perfectly.

    Any help would be great?

    Updated code:

    ~~~~~~~~~~~~~~~~~~~~~~


    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionListener;

    import javax.swing.*;

    import uk.co.futureroute.discovery.projectguibridge.*;

    public class AddPredicateDialog extends JDialog{
    PredicatePanelView predPanelView = null;
    // Table model used
    PredicateTableModel typeContentModel = null;
    //JPanels used
    JPanel containerPanel = null;
    JPanel componentPanel = null;
    JPanel addPredDisplayPanel = null;
    JPanel buttonPanel = null;
    // JLabels
    JLabel addPredNameLabel = new JLabel("");
    JLabel dialogCloseBracketLabel = new JLabel(")");
    // JComboBox
    JComboBox listTypesComBox = new JComboBox();
    // JButtons used
    JButton okButton = new JButton("OK");
    JButton cancelButton = new JButton("Cancel");

    private boolean forEdit;



    public AddPredicateDialog(ActionListener actList, PredicatePanelView predPanelView){
    this.predPanelView = predPanelView;
    init();
    this.okButton.addActionListener(actList);
    }


    public void init(){

    typeContentModel = predPanelView.projGuiBridge.getTypesTableModel();
    addPredDisplayPanel = new JPanel();
    buttonPanel = new JPanel();
    containerPanel = new JPanel();
    componentPanel = new JPanel();
    this.setContentPane(containerPanel);
    this.setTitle("Predicate");
    }



    public void launch(int noOfComboBoxes){
    containerPanel.removeAll();
    containerPanel.setLayout(new GridLayout());
    componentPanel.removeAll();
    addPredDisplayPanel.removeAll();
    addPredDisplayPanel.add(addPredNameLabel);
    //dialogComboBoxList.clear();
    for(int i = 0; i < noOfComboBoxes; i++){
    if(i != 0){
    addPredDisplayPanel.add(new JLabel(","));
    }
    JComboBox dialogArgsComboBox = new JComboBox();
    dialogArgsComboBox.setBackground(Color.WHITE);
    for(int c = 0; c < typeContentModel.getRowCount(); c++){
    String type = typeContentModel.getValueAt(c, 0).toString();
    dialogArgsComboBox.addItem(type);
    }
    addPredDisplayPanel.add(dialogArgsComboBox);
    }
    addPredDisplayPanel.add(dialogCloseBracketLabel);

    buttonPanel.setLayout(new GridLayout(2, 1));
    buttonPanel.add(okButton);
    buttonPanel.add(cancelButton);

    componentPanel.setLayout(new BorderLayout());
    componentPanel.add(addPredDisplayPanel, BorderLayout.CENTER);
    componentPanel.add(buttonPanel, BorderLayout.EAST);

    containerPanel.add(componentPanel);
    this.pack();
    this.validate();
    this.setVisible(true);

    }



    public void launch(Object[] selected){

    this.setVisible(true);
    }


    public void removeDialog(){
    this.setVisible(false);

    }


    public boolean wasForEdit() {
    return this.forEdit;
    }



    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center