0

I'm havin troubles regarding the use of a JTextField into my Jpanel. The main file is Jframe and inside there is a Jpanel, when i hit a button it change the Jpanel to another one with a JTextField and Jtable, the JTextField is the only one who doesn't work, i can't put text inside...it is like uneditable. This is my code from the main panel to the other panel

 private void newClienteActionPerformed(java.awt.event.ActionEvent evt) {                                           
    try {
        // TODO add your handling code here:
        mainPanel.setVisible(false);
        UserJPanel users;
        users = new UserJPanel(this, mainPanel);
        visiblePanel.setVisible(false);
        visiblePanel = users;
        users.setSize(800, 600);
        getContentPane().setLayout(null);
        getContentPane().add(users);
        users.setVisible(true);
        users.repaint();

    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
}                  

It opens another jpanel, this is the one where the jTextField doesn't work

public class UserJPanel extends javax.swing.JPanel {

private JPanel previousPanel = null;
JFrame parent = null;
private Contactos c;
private final JPanel visiblePanel = null;
Contactos users = new Contactos();
ContactosService userService = new ContactosService();

public UserJPanel(JFrame fparent, JPanel pPanel) throws IOException {
    initComponents();
    this.parent = fparent;
    this.previousPanel = pPanel;
    limparJTable();
    preencherTabelaUsers();
}

public void limparJTable() {
    DefaultTableModel model2 = (javax.swing.table.DefaultTableModel) tabela1.getModel();
    model2.setRowCount(0);
}

public void preencherTabelaUsers() throws IOException{
    final RowPopup pop = new RowPopup(this.tabela1);
    this.tabela1.setRowHeight(this.tabela1.getRowHeight() + 10);
    DefaultTableModel tabelaFuncoes = (DefaultTableModel)this.tabela1.getModel();
    final TableRowSorter<DefaultTableModel> sorter = new TableRowSorter<>(tabelaFuncoes);
    this.tabela1.setRowSorter(sorter);
    tabelaFuncoes.setNumRows(0);
    try {
        List<Contactos> usersDados = this.userService.findAll();
        usersDados.stream().forEach(b -> {
            tabelaFuncoes.addRow(new Object[]{b.getIdcontactos(), b.getNome(), b.getApelido(), b.getCc(), b.getNif(), b.getTelefone(),b.getEmail()});
        }
        );
    }
    catch (Exception erro) {
        JOptionPane.showMessageDialog(null, erro);
    }
}


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

    UsersPanel = new javax.swing.JPanel();
    filterFxText = new javax.swing.JTextField();
    searchBT = new javax.swing.JButton();
    jScrollPane1 = new javax.swing.JScrollPane();
    tabela1 = new javax.swing.JTable();

    setMaximumSize(new java.awt.Dimension(750, 500));
    setPreferredSize(new java.awt.Dimension(750, 500));

    UsersPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados Clientes", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 14))); // NOI18N
    UsersPanel.setMaximumSize(new java.awt.Dimension(700, 500));
    UsersPanel.setMinimumSize(new java.awt.Dimension(700, 500));
    UsersPanel.setPreferredSize(new java.awt.Dimension(700, 500));

    filterFxText.setText("Insira um nome");

    searchBT.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/search_16_16.png"))); // NOI18N
    searchBT.setToolTipText("Procurar");

    tabela1.setModel(new javax.swing.table.DefaultTableModel(
        new Object [][] {
            {null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null},
            {null, null, null, null, null, null, null}
        },
        new String [] {
            "ID", "Nome", "Apelido", "CC", "NIF", "Telefone", "Email"
        }
    ) {
        boolean[] canEdit = new boolean [] {
            false, true, true, true, true, true, false
        };

        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return canEdit [columnIndex];
        }
    });
    tabela1.setColumnSelectionAllowed(true);
    jScrollPane1.setViewportView(tabela1);

    javax.swing.GroupLayout UsersPanelLayout = new javax.swing.GroupLayout(UsersPanel);
    UsersPanel.setLayout(UsersPanelLayout);
    UsersPanelLayout.setHorizontalGroup(
        UsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(UsersPanelLayout.createSequentialGroup()
            .addGroup(UsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(UsersPanelLayout.createSequentialGroup()
                    .addComponent(filterFxText, javax.swing.GroupLayout.PREFERRED_SIZE, 600, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(searchBT, javax.swing.GroupLayout.DEFAULT_SIZE, 72, Short.MAX_VALUE))
                .addComponent(jScrollPane1))
            .addContainerGap())
    );
    UsersPanelLayout.setVerticalGroup(
        UsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(UsersPanelLayout.createSequentialGroup()
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(UsersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(filterFxText)
                .addComponent(searchBT, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 413, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(31, 31, 31))
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addComponent(UsersPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addContainerGap())
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(UsersPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 489, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    UsersPanel.getAccessibleContext().setAccessibleParent(UsersPanel);
}// </editor-fold>                        


// Variables declaration - do not modify                     
private javax.swing.JPanel UsersPanel;
private javax.swing.JTextField filterFxText;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton searchBT;
private javax.swing.JTable tabela1;
// End of variables declaration                   

}

Check the image with red rectangle, this where i can insert any text

enter image description here

any help?

UPDATE

The only part who is not working is the jTextField, the Jtable is working properly, check the image

enter image description here

And check jTextField, i have removed the toolTipText and now is empty, but it is unacessable when the program is running... About the layout the initcomponents() method is automatically generated when i put the elements into Jpane

So what's wrong?

  • so you actuall CAN enter text in it? you're being very vague, can you be more concrete? – Stultuske Nov 03 '17 at 10:07
  • No i can't....the text you see is from line 66 - filterFxText.setText("Insira um nome"); –  Nov 03 '17 at 10:11
  • ok ... and what is the other field? the one that "doesn't work"? and where do you try to set a value in that? – Stultuske Nov 03 '17 at 10:14
  • Apart from the unadvisable use of `null` layouts, one of the main reasons that you might not be able to input data (or other wise interact with the UI) is because you're blocking the event dispatching thread in some way – MadProgrammer Nov 03 '17 at 11:05
  • check update above –  Nov 03 '17 at 11:48
  • 2
    1) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). 2) Use a [`CardLayout`](http://download.oracle.com/javase/8/docs/api/java/awt/CardLayout.html) as shown in [this answer](http://stackoverflow.com/a/5786005/418556). 3) Java GUIs have to work on different OS', screen size, screen resolution etc. using different PLAFs in different locales. As such, they are not conducive to pixel perfect layout. Instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556) along with layout padding and .. – Andrew Thompson Nov 03 '17 at 12:40
  • .. borders for [white space](http://stackoverflow.com/a/17874718/418556). 4) Tip: Add @MadProgrammer (or whoever, the `@` is important) to *notify* the person of a new comment. – Andrew Thompson Nov 03 '17 at 12:41

0 Answers0