Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7820367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:15:52+00:00 2026-06-02T07:15:52+00:00

This is kinda a silly question, but I’m beggining with java swing and have

  • 0

This is kinda a silly question, but I’m beggining with java swing and have been doing kinda great, but I really can’t make a JTable appear in my form, so far a blank square appears but no columns at all, here’s a snippet:

DefaultTableModel modelo = new DefaultTableModel();
modelo.setColumnCount(1);
tblTrans = new JTable(modelo);
modelo.addColumn("Prueba");
tblTrans.revalidate();
tblTrans.setBounds(316, 47, 248, 243);
contentPane.add(tblTrans);

Here’s the complete code in case you need it:

package mx.adk.grafos;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.DefaultListModel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.ListSelectionModel;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JList;
import javax.swing.JTable;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Set;
import java.util.TreeSet;

public class GUI extends JFrame implements ActionListener {

    private JPanel contentPane;
    private JTextField txtEstados;
    private JTextField txtLenguaje;
    private JTextField txtFinal;
    private JTable tblTrans;
    private JList lstEstados;
    private JList lstLenguaje;

    DefaultListModel listaEstados;
    TreeSet<String> setEstados = new TreeSet<String>();

    DefaultListModel listaLenguaje;
    TreeSet<Character> setLenguaje = new TreeSet<Character>();

    /*
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    GUI frame = new GUI();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    */

    public void actionPerformed(ActionEvent e) {
        String comando = e.getActionCommand();
        if(comando.equalsIgnoreCase("btnAEstados")){
            String tmp = txtEstados.getText();
            if(setEstados.add(tmp)){
                listaEstados.addElement(tmp);
            }
            return;
        }
        if(comando.equalsIgnoreCase("btneestados")){
            String tmp = (String) lstEstados.getSelectedValue();
            setEstados.remove(tmp);
            listaEstados.removeElement(tmp);
        }
        if(comando.equalsIgnoreCase("btnALenguaje")){
            char tmp = txtLenguaje.getText().charAt(0);
            if(setLenguaje.add(tmp)){
                listaLenguaje.addElement(tmp);
            }
            return;
        }
        if(comando.equalsIgnoreCase("btnelenguaje")){
            char tmp = (char) lstLenguaje.getSelectedValue().toString().charAt(0);
            setLenguaje.remove(tmp);
            listaLenguaje.removeElement(tmp);
        }
    }

    public GUI() {
        setTitle("Automata finito no deterministico");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 599, 368);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        txtEstados = new JTextField();
        txtEstados.setBounds(26, 82, 72, 28);
        contentPane.add(txtEstados);
        txtEstados.setColumns(10);

        JButton btnAEstados = new JButton(">>");
        btnAEstados.setBounds(103, 69, 51, 29);
        contentPane.add(btnAEstados);
        btnAEstados.addActionListener(this);
        btnAEstados.setActionCommand("btnAEstados");

        listaEstados = new DefaultListModel();
        lstEstados = new JList(listaEstados);
        lstEstados.setBounds(154, 46, 105, 109);
        contentPane.add(lstEstados);
        lstEstados.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        JLabel lblEstados = new JLabel("Estados");
        lblEstados.setBounds(83, 19, 59, 16);
        contentPane.add(lblEstados);

        JButton btnEEstados = new JButton("<<");
        btnEEstados.setBounds(103, 96, 51, 29);
        contentPane.add(btnEEstados);
        btnEEstados.addActionListener(this);
        btnEEstados.setActionCommand("btnEEstados");

        JButton btnELenguaje = new JButton("<<");
        btnELenguaje.setBounds(103, 231, 51, 29);
        contentPane.add(btnELenguaje);
        btnELenguaje.addActionListener(this);
        btnELenguaje.setActionCommand("btnELenguaje");

        JButton btnALenguaje = new JButton(">>");
        btnALenguaje.setBounds(103, 204, 51, 29);
        contentPane.add(btnALenguaje);
        btnALenguaje.addActionListener(this);
        btnALenguaje.setActionCommand("btnALenguaje");

        txtLenguaje = new JTextField();
        txtLenguaje.setColumns(10);
        txtLenguaje.setBounds(26, 217, 72, 28);
        contentPane.add(txtLenguaje);

        listaLenguaje = new DefaultListModel();
        lstLenguaje = new JList(listaLenguaje);
        lstLenguaje.setBounds(154, 181, 105, 109);
        contentPane.add(lstLenguaje);
        lstLenguaje.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        JLabel lblLenguaje = new JLabel("Lenguaje");
        lblLenguaje.setBounds(95, 161, 59, 16);
        contentPane.add(lblLenguaje);

        txtFinal = new JTextField();
        txtFinal.setText("QFinal");
        txtFinal.setColumns(10);
        txtFinal.setBounds(26, 298, 72, 28);
        contentPane.add(txtFinal);

        DefaultTableModel modelo = new DefaultTableModel();
        modelo.setColumnCount(1);
        tblTrans = new JTable(modelo);
        modelo.addColumn("Prueba");
        tblTrans.revalidate();
        tblTrans.setBounds(316, 47, 248, 243);
        contentPane.add(tblTrans);

        JLabel lblTransiciones = new JLabel("Transiciones");
        lblTransiciones.setBounds(394, 19, 89, 16);
        contentPane.add(lblTransiciones);

        JButton btnAceptar = new JButton("Aceptar");
        btnAceptar.setBounds(476, 311, 117, 29);
        contentPane.add(btnAceptar);
        btnAceptar.addActionListener(this);
        btnAceptar.setActionCommand("btnAceptar");
    }
}

What I want to accomplish is to add a column for each “Estado” given, the program is about non deterministic automata, and a row for each “Lenguaje” given so I can make the transition matrix, I do know how to make this each time the buttons are pressed, but it appears like the column is being added but it’s not visible at all, just a blank square.

Corrections suggested:

DefaultTableModel modelo = new DefaultTableModel();
        modelo.setColumnCount(1);
        tblTrans = new JTable(modelo);
        panel.add(tblTrans);
        panel.setBounds(316, 47, 248, 243);
        modelo.addColumn("Test");
        tblTrans.revalidate();
        contentPane.add(panel);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:15:54+00:00Added an answer on June 2, 2026 at 7:15 am

    I was right about the scroll pane. This is working for me:

        DefaultTableModel modelo = new DefaultTableModel();
        modelo.setColumnCount(1);
        modelo.addColumn("Prueba");
        tblTrans = new JTable(modelo);
        JScrollPane sPane = new JScrollPane(tblTrans);
        sPane.setBounds(316, 47, 248, 243);
        contentPane.add(sPane);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe this question is kind of silly but I have no clue how to
I feel kind of silly asking this question as it seems really simple, but
This may seem a silly question, but having been pondering it for a few
Okay, I'm kinda stuck on really silly problem, but still can't figure out. I'm
i know this is kinda retarded but I just can't figure it out. I'm
This question is kinda aimed towards PHP but it probably applies to other languages
This might seem to be a silly question at first, but please read on.
I know this might sound silly but I have no idea how to do
I'm kinda new to jQuery, so this may be a silly question... My problem
This is probably a silly question, but I am having a hard time finding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.