NOVINKA - Online rekvalifikační kurz Python programátor. Oblíbená a studenty ověřená rekvalifikace - nyní i online.
Hledáme nové posily do ITnetwork týmu. Podívej se na volné pozice a přidej se do nejagilnější firmy na trhu - Více informací.

Diskuze – Lekce 2 - Java Swing pod pokličkou

Zpět

Upozorňujeme, že diskuze pod našimi online kurzy jsou nemoderované a primárně slouží k získávání zpětné vazby pro budoucí vylepšení kurzů. Pro studenty našich rekvalifikačních kurzů nabízíme možnost přímého kontaktu s lektory a studijním referentem pro osobní konzultace a podporu v rámci jejich studia. Toto je exkluzivní služba, která zajišťuje kvalitní a cílenou pomoc v případě jakýchkoli dotazů nebo projektů.

Komentáře
Avatar
Tomhaus
Člen
Avatar
Tomhaus:16.7.2014 16:29

mě se nechce zobrazit ten vypsanej text

package clicker.graphics;

import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JPanel;

public class Screen extends JPanel {
        private static final long serialVersionUID = 1L;

        private static final int WIDTH = 300, HEIGHT = 200;

        private JLabel panel01;

        public Screen(){
                setFocusable(true);
                setPreferredSize(new Dimension(WIDTH, HEIGHT));

                display();
        }

        public void display(){
                panel01 = new JLabel();
                panel01.setText("ahoj");

        }

}
Editováno 16.7.2014 16:32
Odpovědět
16.7.2014 16:29
Být lepší a chytřejší je důležité, ale někdy se musíme spokojit s tím, co máme.
Avatar
Tomhaus
Člen
Avatar
Odpovídá na Tomhaus
Tomhaus:16.7.2014 16:49

ahh.. už sem na to přišel, musim to přidat add

Odpovědět
16.7.2014 16:49
Být lepší a chytřejší je důležité, ale někdy se musíme spokojit s tím, co máme.
Avatar
Djejsi
Člen
Avatar
Djejsi:21.1.2019 19:59

Zdravim preco ked urobim to ze pridam vycentrovanie tak mi to vypisuje errory ale tebe v tom HelloSwing2 ked stiahnem tak to ide bez chyby? Pritom som nic neupravoval podla seba.

public class HlavniJframe extends javax.swing.JFrame {

    /**
     * Creates new form HlavniJframe
     */
    public HlavniJframe() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Pozdrav");

        jLabel1.setText("Pozdrav z formulare");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(156, 156, 156)
                .addComponent(jLabel1)
                .addContainerGap(148, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(134, 134, 134)
                .addComponent(jLabel1)
                .addContainerGap(152, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(HlavniJframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(HlavniJframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(HlavniJframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(HlavniJframe.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                HlavniJFrame hlavniJFrame = new HlavniJFrame();
                hlavniJFrame.setLocationRelativeTo(null);
                hlavniJFrame.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JLabel jLabel1;
    // End of variables declaration
}

Errory:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: HlavniJFrame
        at HlavniJframe$1.run(HlavniJframe.java:86)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
        at java.awt.EventQueue.access$500(EventQueue.java:97)
        at java.awt.EventQueue$3.run(EventQueue.java:709)
        at java.awt.EventQueue$3.run(EventQueue.java:703)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
 
Odpovědět
21.1.2019 19:59
Avatar
Martin Velc
Člen
Avatar
Odpovídá na Djejsi
Martin Velc:11.8.2019 10:08

Máš třídu nazvanou HlavniJframe, ale dole nastavuješ HlavniJFrame. Rozdíl je velké/malé F ve slově Frame.

 
Odpovědět
11.8.2019 10:08
Avatar
Jan Knězů
Člen
Avatar
Jan Knězů:18.11.2021 18:40

Chci si vytvořit složku Other Sources se složkou src/main/resources jako je v skriptu po kliknutí na projekt a zadání new folder vyplním src/main/resources finish tuto složku nevidím proč?
Palette a Properties si chci umístit do prava jako v návodu ve view je nemám proč?

 
Odpovědět
18.11.2021 18:40
Avatar
Václav Pešek:26.1.2022 20:19

Minimální velikost
Po implementaci:

HlavniJFrame hlavniJFrame = new HlavniJFrame();
hlavniJFrame.setMinimumSize(hlavniJFrame.getSize());

by mělo platit: "Takto vytvořené okno půjde ručně libovolně zvětšovat, ale zmenšit půjde jen do velikosti, v jaké se otevřelo."
Mně ale jde zmenšit víc, a sice tak, že limitující je, aby byly vidět vložené objekty (zde "Pozdrav z formuláře"), Jinými slovy: okno lze zmenšit oproti prvotnímu otevření. Netuší někdo, kde může být chyba?
Václav

 
Odpovědět
26.1.2022 20:19
Avatar
Atrament
Člen
Avatar
Odpovídá na Václav Pešek
Atrament:26.1.2022 22:29

Ukaž celý kód

 
Odpovědět
26.1.2022 22:29
Avatar
Odpovídá na Atrament
Václav Pešek:26.1.2022 23:49

Zde je celý kód:

package cz.itnetwork.helloswing;

import java.awt.Dimension;
import javax.swing.ImageIcon;

/**
 *
 * @author va057280
 */
public class HlavniJFrame extends javax.swing.JFrame {

    /**
     * Creates new form HlavniJFrame
     */
    public HlavniJFrame() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Pozdrav");

        jLabel1.setText("Pozdrav z formuláře");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(136, 136, 136)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(150, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(81, 81, 81)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(138, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(HlavniJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(HlavniJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(HlavniJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(HlavniJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            //public void run() {
            //    new HlavniJFrame().setVisible(true);
            //}
            public void run() {
                HlavniJFrame hlavniJFrame = new HlavniJFrame();
                hlavniJFrame.setMinimumSize(hlavniJFrame.getSize());
                hlavniJFrame.setLocationRelativeTo(null);
                hlavniJFrame.setVisible(true);
                ImageIcon icon = new ImageIcon(getClass().getResource("/Logo_Mates.png"));
                hlavniJFrame.setIconImage(icon.getImage());
                //hlavniJFrame.setResizable(false);
                //hlavniJFrame.setMinimumSize(new Dimension(100,100));

            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JLabel jLabel1;
    // End of variables declaration
}
 
Odpovědět
26.1.2022 23:49
Avatar
Atrament
Člen
Avatar
Odpovídá na Václav Pešek
Atrament:27.1.2022 1:03

Zkouším to a nevidím žádný problém, funguje to přesně jak má, okno které se mi otevře nejde zmenšit pod velikost s jakou se otevřelo...

 
Odpovědět
27.1.2022 1:03
Avatar
Neaktivní uživatel:10.1.2023 18:32

Prosím, prosím. Nikde na netu jsem nenašla důvod ani příčinu, proč se mi nezobrazuje po runu aplikace její okno, jde nahlédnout v Preview, ale nezobrazuje mi to přidanou grafiku (ikonu, stejná velikost).

Odpovědět
10.1.2023 18:32
Neaktivní uživatelský účet
Děláme co je v našich silách, aby byly zdejší diskuze co nejkvalitnější. Proto do nich také mohou přispívat pouze registrovaní členové. Pro zapojení do diskuze se přihlas. Pokud ještě nemáš účet, zaregistruj se, je to zdarma.

Zobrazeno 10 zpráv z 11.