[nbusers] Can't get text to display in JTextArea.

  • From: "RwGWiccan" < >
  • To:
  • Subject: [nbusers] Can't get text to display in JTextArea.
  • Date: Fri, 26 Oct 2012 21:30:40 -0400

Trying this for a class. I am using the newest IDE and cannot get the text to 
show up in the JTextArea of the JFrame. the code is as follows:


Code:
package dvdinventory5;

import javax.swing.*;

import java.awt.event.*;

/**
 *
 * @author Wiccan
 */
public class DVDInv5UI extends javax.swing.JFrame {
        private JTextArea txt;
        private Inventory inv;
        private int currentDisplay = 0;
        
    /**
     * Creates new form DVDInv5UI
     */
    public DVDInv5UI() {
                super("DVD");
                setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); 
// quit if the window is closed
                initComponents();
                init();
    }
    
    public void init() {
        // make a couple products
                ExtendedDVD p1 = new ExtendedDVD(1,"Back to the 
Future.",3,15.49,"Robert Zemeckis");
                ExtendedDVD p2 = new ExtendedDVD(2,"Howard the 
Duck.",7,17.29,"Willard Huyck");
                ExtendedDVD p3 = new ExtendedDVD(3,"Phenomenon",1,15.29,"Jon 
Turteltaub");
                ExtendedDVD p4 = new 
ExtendedDVD(4,"Prometheus",2,19.99,"Ridley Scott");
                //make inventory and put them in:
                inv = new Inventory();
                inv.add(p1);
                inv.add(p2);
                inv.add(p3);
                inv.add(p4);
                
                inv.sort();
    }

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

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("First Item");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("Previous");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Last Item");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Next");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Exit");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout layout = new 
javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, 
layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, 
Short.MAX_VALUE)
                .addComponent(jButton5)
                .addGap(167, 167, 167))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2)
                        .addGap(59, 59, 59)
                        .addComponent(jButton4)
                        .addGap(18, 18, 18)
                        .addComponent(jButton3)
                        .addGap(0, 1, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, 
javax.swing.GroupLayout.PREFERRED_SIZE, 212, 
javax.swing.GroupLayout.PREFERRED_SIZE)
                
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton4)
                    .addComponent(jButton3))
                .addGap(18, 18, 18)
                .addComponent(jButton5)
                .addGap(0, 11, Short.MAX_VALUE))
        );

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

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {    
                                     
                if (currentDisplay > 0) {
                                currentDisplay--;
                            }
                                else {
                                currentDisplay = inv.size()-1;
                            }
                                displayDVD();
    }                                        

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {    
                                     
       System.exit (0);
    }                                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {    
                                     
            currentDisplay = 0;// go to the beginning
            displayDVD();                        
    
    }                                        

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {    
                                     
                if (currentDisplay < inv.size()-1) {
                                currentDisplay++;
                            } //advance to the end
                                else {
                                currentDisplay = 0;
                            }
                                displayDVD();
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {    
                                     
                currentDisplay = inv.size()-1;
                displayDVD();
    }                                        

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {        
                              
        // TODO add your handling code here:
    }                                     

    /**
     * @param args the command line arguments
     */
    public void displayDVD() {
        txt.setEditable(false);
                txt.setText("DVD Details:\n");
                txt.append("Item number: " + 
inv.get(currentDisplay).getdvdNumber() + "\n");
                txt.append("DVD name: " + 
inv.get(currentDisplay).getdvdName() + "\n");
                txt.append("Units in stock: " + 
inv.get(currentDisplay).getQuantity() + "\n");
                txt.append("Price: $" + 
String.format("%.2f",inv.get(currentDisplay).getPrice()) + "\n");
                txt.append("Total value: $" + 
String.format("%.2f",inv.get(currentDisplay).getInventoryValue()) + "\n");
                txt.append("Fee: $" + 
String.format("%.2f",inv.get(currentDisplay).getInventoryValue()*0.05) + 
"\n\n");
        
                txt.append("Total value: $" + 
String.format("%.2f",inv.value()));
   
    }
    
    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(DVDInv5UI.class.getName()).log(java.util.logging.Level.SEVERE,
 null, ex);
        } catch (InstantiationException ex) {
            
java.util.logging.Logger.getLogger(DVDInv5UI.class.getName()).log(java.util.logging.Level.SEVERE,
 null, ex);
        } catch (IllegalAccessException ex) {
            
java.util.logging.Logger.getLogger(DVDInv5UI.class.getName()).log(java.util.logging.Level.SEVERE,
 null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            
java.util.logging.Logger.getLogger(DVDInv5UI.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 DVDInv5UI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration




}




there are obviously more java files for it, but I thought the JFrame code 
would be enough.






[nbusers] Can't get text to display in JTextArea.

RwGWiccan 10/27/2012

[nbusers] Re: Can't get text to display in JTextArea.

Jeffrey H. Coffield 10/28/2012

[nbusers] Re: Can't get text to display in JTextArea.

Bayless Kirtley 10/28/2012

[nbusers] Can't get text to display in JTextArea.

RwGWiccan 10/29/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close