Problem z wyświetlaniem tekstu na buttonie (NetBeans)

0

Witam.
Zaczynam się uczyć Javy, ale z podstawowymi sprawami jak dotąd sobie radziłem, aż do dziś...
Mam problem z wyświetlaniem tekstu na buttonie (używam NetBeans).
Utworzyłem formę aplikacji, dodaję (kolejny już button), wpisuję odpowiedni tekst. Uruchamiam mój program, widać przycisk, ale bez wpisanego tekstu (pusty).
Gdy wybiorę "Preview design" przycisk jest wyświetlany poprawnie. Mam też dodane wcześniej buttony i też są poprawnie wyświetlane (bez względu czy kliknę Run Project czy Preview Design). Nie mogę jednak dodać nowego buttona tak, żeby było widać na nim tekst. Mogę zmieniać inne właściwości związane z wyglądem przycisku - one są wyświetlane poprawnie.
Nawet jeśli skopiuję istniejący już przycisk na formie, to ten 'stary' ma tekst, a 'nowy' po uruchomieniu programu go nie ma, mimo iż wszystkie właściwości są takie same.

Czy ktoś może mi wyjaśnić o co w tym chodzi?

Artur

0

kod

0

Kod formy poniżej. Praktycznie całość wygenerowana w widoku 'Design', ręcznie nie klepałem, więc popsuć raczej nie mogłem.
Button utworzony wcześniej (wyświetlany poprawnie) nazywa się jBtn_Sprawdz.
Button, który utworzyłem poprzez kopiowanie wymienionego wyżej nazywa się jBtn_Sprawdz1 i nie wyświetla tekstu.

Ciekawostka (być może pomocna): jeśli przed uruchomieniem projektu wykonam 'Clean and Build Project', to teksty na przyciskach są już widoczne.

/*
 * LangTestView.java
 */

package langtest;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import java.io.*;
import javax.swing.JOptionPane;

/**
 * The application's main frame.
 */
public class LangTestView extends FrameView {

    
    public LangTestView(SingleFrameApplication app) {
        super(app);

        initComponents();

        
        
        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
        this.getRootPane().setDefaultButton(jBtn_Sprawdz);
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = LangTestApp.getApplication().getMainFrame();
            aboutBox = new LangTestAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        LangTestApp.getApplication().show(aboutBox);
    }

    /** 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() {

        mainPanel = new javax.swing.JPanel();
        jTF_Pytanie = new javax.swing.JTextField();
        jTF_Odpowiedz = new javax.swing.JTextField();
        jBtn_Sprawdz = new javax.swing.JButton();
        jPanel_Odpowiedzi = new javax.swing.JPanel();
        jLbl1 = new javax.swing.JLabel();
        jPB_OdpowiedziPoprawne = new javax.swing.JProgressBar();
        jLbl2 = new javax.swing.JLabel();
        jPB_OdpowiedziOgolem = new javax.swing.JProgressBar();
        jLbl_OdpowiedziPoprawne = new javax.swing.JLabel();
        jLbl_OdpowiedziOgolem = new javax.swing.JLabel();
        jBtn_Sprawdz1 = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        otworzMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        jFileChooser1 = new javax.swing.JFileChooser();
        btnGroup_SwitchLang = new javax.swing.ButtonGroup();

        mainPanel.setMaximumSize(new java.awt.Dimension(400, 400));
        mainPanel.setMinimumSize(new java.awt.Dimension(300, 300));
        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setPreferredSize(new java.awt.Dimension(400, 400));

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(langtest.LangTestApp.class).getContext().getResourceMap(LangTestView.class);
        jTF_Pytanie.setText(resourceMap.getString("jTF_Pytanie.text")); // NOI18N
        jTF_Pytanie.setAutoscrolls(false);
        jTF_Pytanie.setEnabled(false);
        jTF_Pytanie.setName("jTF_Pytanie"); // NOI18N
        jTF_Pytanie.setPreferredSize(new java.awt.Dimension(200, 20));

        jTF_Odpowiedz.setText(resourceMap.getString("jTF_Odpowiedz.text")); // NOI18N
        jTF_Odpowiedz.setName("jTF_Odpowiedz"); // NOI18N
        jTF_Odpowiedz.setPreferredSize(new java.awt.Dimension(200, 20));

        jBtn_Sprawdz.setText(resourceMap.getString("jBtn_Sprawdz.text")); // NOI18N
        jBtn_Sprawdz.setEnabled(false);
        jBtn_Sprawdz.setName("jBtn_Sprawdz"); // NOI18N
        jBtn_Sprawdz.setNextFocusableComponent(jTF_Odpowiedz);
        jBtn_Sprawdz.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn_SprawdzActionPerformed(evt);
            }
        });

        jPanel_Odpowiedzi.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel_Odpowiedzi.border.title"))); // NOI18N
        jPanel_Odpowiedzi.setName("jPanel_Odpowiedzi"); // NOI18N

        jLbl1.setText(resourceMap.getString("jLbl1.text")); // NOI18N
        jLbl1.setName("jLbl1"); // NOI18N

        jPB_OdpowiedziPoprawne.setName("jPB_OdpowiedziPoprawne"); // NOI18N

        jLbl2.setText(resourceMap.getString("jLbl2.text")); // NOI18N
        jLbl2.setName("jLbl2"); // NOI18N

        jPB_OdpowiedziOgolem.setName("jPB_OdpowiedziOgolem"); // NOI18N

        jLbl_OdpowiedziPoprawne.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLbl_OdpowiedziPoprawne.setText(resourceMap.getString("jLbl_OdpowiedziPoprawne.text")); // NOI18N
        jLbl_OdpowiedziPoprawne.setName("jLbl_OdpowiedziPoprawne"); // NOI18N

        jLbl_OdpowiedziOgolem.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLbl_OdpowiedziOgolem.setText(resourceMap.getString("jLbl_OdpowiedziOgolem.text")); // NOI18N
        jLbl_OdpowiedziOgolem.setName("jLbl_OdpowiedziOgolem"); // NOI18N

        javax.swing.GroupLayout jPanel_OdpowiedziLayout = new javax.swing.GroupLayout(jPanel_Odpowiedzi);
        jPanel_Odpowiedzi.setLayout(jPanel_OdpowiedziLayout);
        jPanel_OdpowiedziLayout.setHorizontalGroup(
            jPanel_OdpowiedziLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_OdpowiedziLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel_OdpowiedziLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLbl1)
                    .addComponent(jLbl2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel_OdpowiedziLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel_OdpowiedziLayout.createSequentialGroup()
                        .addComponent(jPB_OdpowiedziPoprawne, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLbl_OdpowiedziPoprawne, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel_OdpowiedziLayout.createSequentialGroup()
                        .addComponent(jPB_OdpowiedziOgolem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLbl_OdpowiedziOgolem, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(280, 280, 280))
        );
        jPanel_OdpowiedziLayout.setVerticalGroup(
            jPanel_OdpowiedziLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_OdpowiedziLayout.createSequentialGroup()
                .addGroup(jPanel_OdpowiedziLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel_OdpowiedziLayout.createSequentialGroup()
                        .addComponent(jLbl1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLbl2))
                    .addGroup(jPanel_OdpowiedziLayout.createSequentialGroup()
                        .addComponent(jPB_OdpowiedziPoprawne, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPB_OdpowiedziOgolem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel_OdpowiedziLayout.createSequentialGroup()
                        .addComponent(jLbl_OdpowiedziPoprawne)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLbl_OdpowiedziOgolem)))
                .addContainerGap(13, Short.MAX_VALUE))
        );

        jBtn_Sprawdz1.setText(resourceMap.getString("jBtn_Sprawdz1.text")); // NOI18N
        jBtn_Sprawdz1.setEnabled(false);
        jBtn_Sprawdz1.setName("jBtn_Sprawdz1"); // NOI18N
        jBtn_Sprawdz1.setNextFocusableComponent(jTF_Odpowiedz);
        jBtn_Sprawdz1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtn_Sprawdz1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTF_Odpowiedz, javax.swing.GroupLayout.DEFAULT_SIZE, 486, Short.MAX_VALUE)
                            .addComponent(jTF_Pytanie, javax.swing.GroupLayout.DEFAULT_SIZE, 486, Short.MAX_VALUE)
                            .addComponent(jBtn_Sprawdz)
                            .addComponent(jBtn_Sprawdz1)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel_Odpowiedzi, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGap(54, 54, 54)
                .addComponent(jTF_Pytanie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTF_Odpowiedz, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBtn_Sprawdz)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBtn_Sprawdz1)
                .addGap(32, 32, 32)
                .addComponent(jPanel_Odpowiedzi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        otworzMenuItem.setText(resourceMap.getString("otworzMenuItem.text")); // NOI18N
        otworzMenuItem.setName("otworzMenuItem"); // NOI18N
        otworzMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                otworzMenuItemActionPerformed(evt);
            }
        });
        fileMenu.add(otworzMenuItem);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(langtest.LangTestApp.class).getContext().getActionMap(LangTestView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 544, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 374, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        jFileChooser1.setApproveButtonText(resourceMap.getString("jFileChooser1.approveButtonText")); // NOI18N
        jFileChooser1.setDialogTitle(resourceMap.getString("jFileChooser1.dialogTitle")); // NOI18N
        jFileChooser1.setName("jFileChooser1"); // NOI18N

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>
                                            
    
    
    // Variables declaration - do not modify
    private javax.swing.JButton jBtn_Sprawdz;
    private javax.swing.JButton jBtn_Sprawdz1;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JLabel jLbl1;
    private javax.swing.JLabel jLbl2;
    private javax.swing.JLabel jLbl_OdpowiedziOgolem;
    private javax.swing.JLabel jLbl_OdpowiedziPoprawne;
    private javax.swing.JProgressBar jPB_OdpowiedziOgolem;
    private javax.swing.JProgressBar jPB_OdpowiedziPoprawne;
    private javax.swing.JPanel jPanel_Odpowiedzi;
    private javax.swing.JTextField jTF_Odpowiedz;
    private javax.swing.JTextField jTF_Pytanie;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem otworzMenuItem;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}

Dziękuję za zainteresowanie tematem.

0

W resourceMap jest "jBtn_Sprawdz1.text"?
Rada na przyszłość, formatuj kod przed wklejeniem, obowiązkowo wyrzuć puste wiersze.

0

Przypadkiem, szukając na google informacji o ResourceMap, natknąłem sie na wyjaśnienie mojego problemu:
http://stackoverflow.com/questions/2043756/netbeans-java-resourcemap-getstring-returning-null

1 użytkowników online, w tym zalogowanych: 0, gości: 1