Organize items within Jtexarea

Asked

Viewed 94 times

-1

How do I pick up items from a combobox and place in a jTextArea, one below the other?

Follows my code:

public class PW_XML extends javax.swing.JFrame {

    int Grade;
    int Frequencia;
    int AttackRN;
    int DistanciaFrag;
    int PHAttackMin;
    int PHAttackMax;
    int MGAttackMin;
    int MGAttackMax;
    int DurabilidadeMin;
    int DurabilidadeMax;
    int LVLReq;
    int STRReq;
    int CONReq;
    int AGIReq;
    int INTReq;
    int Ref12;
    int Ref;
    int BonusList;
    int Bonus;
    int Sockets;
    int Multiply;
    int ItemID;
    int Prof;
    String Maker;
    String SubType;
    String ItemName;

    public PW_XML() {
        initComponents();
    }

    private void btnDelGenerateActionPerformed(java.awt.event.ActionEvent evt) {                                               
        //JPCodigoGerado.setText("");
    }                                              

    private void btnResetAllActionPerformed(java.awt.event.ActionEvent evt) {                                            
        JtfSubType.setText("");
        JtfItemName.setText("");
        JtfGrade.setText("");
        JtfFrequencia.setText("");
        JtfAttackRN.setText("");
        JtfDistanciaFrag.setText("");
        JtfPHAttackMin.setText("");
        JtfPHAttackMax.setText("");
        JtfMGAttackMin.setText("");
        JtfMGAttackMax.setText("");
        JtfDurabilidadeMin.setText("");
        JtfDurabilidadeMax.setText("");
        JtfLVLReq.setText("");
        JtfSTRReq.setText("");
        JtfCONReq.setText("");
        JtfAGIReq.setText("");
        JtfINTReq.setText("");
        JtfReff.setText("");
        JtfRef.setText("");
        JtfSockets.setText("");
        JtfMultiply.setText("");
        JtfBonus.setText("");
        JtaBonusList.setText("");
        JtfItemID.setText("");
        JtfProf.setText("");
        JtfMaker.setText("");
    }                                           

    private void btnDelActionPerformed(java.awt.event.ActionEvent evt) {                                       
        JtaBonusList.setText("");
    }                                      

    private void btnUPActionPerformed(java.awt.event.ActionEvent evt) {                                      

    }                                     

    private void btnDownActionPerformed(java.awt.event.ActionEvent evt) {                                        

    }                                       

    private void btnGenerateActionPerformed(java.awt.event.ActionEvent evt) {                                            

    }                                           

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {                                       

        JtaBonusList.setText (Jcb2AddItens.getSelectedItem().toString());
        JtaBonusList.setText (Jcb2AddItens.getSelectedItem() + JtfBonus.getText());        
        JtfSubType.setText (Jcb4SubType.getSelectedItem().toString());
        JtfItemName.setText (Jcb5ItemName.getSelectedItem().toString());        
    }                                      

    private void btnDelBonusActionPerformed(java.awt.event.ActionEvent evt) {                                            
        JtfBonus.setText("");
    }                                           

    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(PW_XML.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PW_XML.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PW_XML.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PW_XML.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

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

    // Variables declaration - do not modify                     
    private javax.swing.JComboBox<String> Jcb2AddItens;
    private javax.swing.JComboBox<String> Jcb3Type;
    private javax.swing.JComboBox<String> Jcb4SubType;
    private javax.swing.JComboBox<String> Jcb5ItemName;
    private javax.swing.JPanel JpCodigoGerado;
    private javax.swing.JTextArea JtaBonusList;
    private javax.swing.JTextField JtfAGIReq;
    private javax.swing.JTextField JtfAttackRN;
    private javax.swing.JTextField JtfBonus;
    private javax.swing.JTextField JtfCONReq;
    private javax.swing.JTextField JtfDistanciaFrag;
    private javax.swing.JTextField JtfDurabilidadeMax;
    private javax.swing.JTextField JtfDurabilidadeMin;
    private javax.swing.JTextField JtfFrequencia;
    private javax.swing.JTextField JtfGrade;
    private javax.swing.JTextField JtfINTReq;
    private javax.swing.JTextField JtfItemID;
    private javax.swing.JTextField JtfItemName;
    private javax.swing.JTextField JtfLVLReq;
    private javax.swing.JTextField JtfMGAttackMax;
    private javax.swing.JTextField JtfMGAttackMin;
    private javax.swing.JTextField JtfMaker;
    private javax.swing.JTextField JtfMultiply;
    private javax.swing.JTextField JtfPHAttackMax;
    private javax.swing.JTextField JtfPHAttackMin;
    private javax.swing.JTextField JtfProf;
    private javax.swing.JTextField JtfRef;
    private javax.swing.JTextField JtfReff;
    private javax.swing.JTextField JtfSTRReq;
    private javax.swing.JTextField JtfSockets;
    private javax.swing.JTextField JtfSubType;
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnDel;
    private javax.swing.JButton btnDelBonus;
    private javax.swing.JButton btnDelGenerate;
    private javax.swing.JButton btnDown;
    private javax.swing.JButton btnGenerate;
    private javax.swing.JButton btnResetAll;
    private javax.swing.JButton btnUP;
    private javax.swing.JComboBox<String> cb1Connect;
    private java.awt.Checkbox cbMultiply;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollBar jScrollBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lbl1;
    private javax.swing.JLabel lbl2;
    private javax.swing.JLabel lblAGIReq;
    private javax.swing.JLabel lblAttackRN;
    private javax.swing.JLabel lblBonus;
    private javax.swing.JLabel lblBonusList;
    private javax.swing.JLabel lblCONReq;
    private javax.swing.JLabel lblConnect;
    private javax.swing.JLabel lblDesenvolvidopor;
    private javax.swing.JLabel lblDistanciaFrag;
    private javax.swing.JLabel lblDurabilidade;
    private javax.swing.JLabel lblFrequencia;
    private javax.swing.JLabel lblGiovaniVChaves;
    private javax.swing.JLabel lblGrade;
    private javax.swing.JLabel lblINTReq;
    private javax.swing.JLabel lblItemID;
    private javax.swing.JLabel lblItemName;
    private javax.swing.JLabel lblLVLReq;
    private javax.swing.JLabel lblMGAttack;
    private javax.swing.JLabel lblMaker;
    private javax.swing.JLabel lblPHAttack;
    private javax.swing.JLabel lblProf;
    private javax.swing.JLabel lblProgramador;
    private javax.swing.JLabel lblSTRReq;
    private javax.swing.JLabel lblSockets;
    private javax.swing.JLabel lblSubType;
    private javax.swing.JLabel lblType;
    // End of variables declaration                   
}

pegar do combobox e adicionar na jTextArea um abaixo do outro

  • You edited the question but have not yet provided a code that is [mcve]. How do you expect us to help you if we can’t even test the code? Go to link to learn how to create an example and then edit the question.

  • Giovani, this code is not executable. I recommend that you read the link I passed in the previous comment. There is no way to help you if you do not provide the necessary to analyze the code.

  • And this code does not make any sense, You can add to several text fields, there is nothing jtextarea there

  • There’s a lot I haven’t been able to do yet. As it appears in the photo, above the combobox I used a jTextArea, and wanted to put the items that are inside this combobox in this jTextArea, but one below the other....

  • Giovani how will we help you if you don’t even execute this code? That’s why I’m giving you directions to read the link and provide a [mcve], or it is difficult to understand the code better.

1 answer

0


You did not provide a Minimum, Complete and Verifiable Example then I will provide a generic answer, if I cannot adapt, provide an example as the link above so that it is possible to analyze your problem in specific.

To add text in JTextArea, you do not normally use the method setText() and yes append(). Only by just passing the text to this method, it will concatenate the texts sequentially, then you can add a line break between the items to be displayed to circumvent this behavior, using the method System.getProperty("line.separator"):

suaTextArea.append("algum texto");
suaTextArea.append(System.getProperty("line.separator"));
suaTextArea.append("outro texto");

This way, you will insert the text (as long as the width of your textarea is the length of the strings) as below:

inserir a descrição da imagem aqui

  • Thanks, solved my problem.

  • @Giovani if the answer has solved, you can accept it by clicking on v to the side, so that it serves as a reference for others who consult.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.