Announcement

Collapse
No announcement yet.

Unterschied JFrame vs JDialog

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unterschied JFrame vs JDialog

    Hallo Leute,
    habe gerade ein komisches Problem.

    Ich erstelle JDialog und JFrame, aber mein inhalt wird nur im Frame angezeigt warum?

    Aufgerufen wird das ganze aus einer anderen Klasse..über diesen aufruf

    new SearchResultDialog(resultlistOfFiles,applicationFr ame);

    Das ist die klasse...
    über etwaige hilfe freue ich mich sehr!


    public class SearchResultDialog
    extends JDialog
    {
    //~ Constructors .................................................. .................................................. .......

    /**
    * Creates a new SearchResult object.
    *
    * @param searchResult List of search-result files.
    * @param frame Frame to show this dialog in.
    */
    public SearchResultDialog( List<File> searchResult, JFrame frame )
    {
    super( frame );

    setTitle( "Suchergebnis" );
    _searchResult = searchResult;
    initDialog();
    }

    //~ Methods .................................................. .................................................. ............

    /**
    * Init the searchResult frame.
    */
    private void initDialog()
    {
    // _gl = new GridBagLayout();
    // getContentPane().setLayout( _gl );


    // TODO show result list here with possibility to open each file directly
    JTextArea _textArea = new JTextArea();
    final JScrollPane scroller = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    scroller.setViewportView(_textArea);
    scroller.setSize(300,300);

    Iterator<File> listIterator = _searchResult.iterator();
    int i = 0;
    while (listIterator.hasNext()) {
    File f = listIterator.next();
    _textArea.append(f.getAbsolutePath()+"\n\r");
    i++;
    }
    _textArea.append("\n\r"+i+" files found");

    setSize(300,300);
    setMaximumSize(new Dimension(300,300));
    JFrame _resultFrame = new JFrame();
    _resultFrame.setSize(300,300);
    _resultFrame.add(scroller);
    _resultFrame.setVisible(true);
    //
    JPanel jp = new JPanel();
    jp.add(scroller);
    jp.setMaximumSize(new Dimension(300,300));
    JApplicationView.centerOnScreen(_resultFrame);
    JApplicationView.centerOnScreen(this);
    add(jp);
    pack();
    setVisible(true);
    } // end method initDialog

    //~ Instance variables .................................................. .................................................. .

    /**
    * LayoutManager for search result frame.
    */
    private GridBagLayout _gl;

    /**
    * List of search-result files to display in this dialog.
    */
    private List<File> _searchResult;
    } // end class SearchResultDialog

  • #2
    a) Gibt es hier eine Codeformatierung
    b) Die Benutzung eines _ vor den Variablennamen entspricht keiner üblichen Formatierung mehr
    c) kann ich nicht erkennen wo du einen JDialog erstellst?
    d) Warum wird in einer Klasse die von JDialog abgeleitet ist, ein JFrame erstellt?
    e) schon mal über eine visuelle IDE nachgedacht, bei der solche Probleme nicht auftreten? http://www.netbeans.org/

    Ein JDialog mit einem Button:

    Code:
    public class NewJDialog extends javax.swing.JDialog {
    public NewJDialog(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    }
    @SuppressWarnings("unchecked")
    private void initComponents() {
    jButton1 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstan ts.DISPOSE_ON_CLOSE);
    jButton1.setText("jButton1");
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jButton1)
    .addContainerGap(317, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jButton1)
    .addContainerGap(266, Short.MAX_VALUE))
    );
    pack();
    }
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    NewJDialog dialog = new NewJDialog(new javax.swing.JFrame(), true);
    dialog.addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent e) {
    System.exit(0);
    }
    });
    dialog.setVisible(true);
    }
    });
    }
    private javax.swing.JButton jButton1;
    }[/highlight]
    
    Ein JFrame:
    
    [highlight=java]public class NewJFrame extends javax.swing.JFrame {
    public NewJFrame() {
    initComponents();
    }
    
    
    private void initComponents() {
    jButton1 = new javax.swing.JButton();
    setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
    jButton1.setText("jButton1");
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jButton1)
    .addContainerGap(317, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jButton1)
    .addContainerGap(266, Short.MAX_VALUE))
    );
    pack();
    }
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new NewJFrame().setVisible(true);
    }
    });
    }
    
    private javax.swing.JButton jButton1;
    Der grundsätzliche Unterschied ist, dass JFrame ein Hauptfenster einer Anwendung darstellt
    Zuletzt editiert von Christian Marquardt; 17.06.2020, 13:25.
    Christian

    Comment

    Working...
    X