Place a table created in an existing container

Asked

Viewed 144 times

1

need help!

I’m developing an application in college that will use Bubblesort - yes! We had the misfortune to catch this one! - to draw some data within a table.

I created the table through a class that extended Abstracttablemodel, but I can’t make it stay in the jPanel that I created with Swing. Does anyone know how to solve ?

https://github.com/irom-theprogrammer/ProgramaDengueV3

At this link is the netbeans project - the code is a bit messy. I hope you understand.

In the 'table' package are the table definition classes. In the 'screen' package is the Telaregistrar class - which is the class I’m trying to place the table in. Base on it.

I appreciate the attention of those who can help.

  • You must place the table inside a Jscrollpane, not inside a Jpanel.

  • The table is inside Jpanel and this is inside Jscrollpane.

  • This order is wrong, jtables are special components that can increase in size according to the data contained in it, should be placed inside an adaptive container, otherwise they will not display the columns correctly (will not display the header) and not all rows in the table. Invert this order ai, jtabel should be inserted straight into jscrollpane.

  • 1

    Wouldn’t it have been better to put the source code here? You don’t have to take the link from github, but putting the source code would be better. Also, seriously you want to use Bubblesort? With so much ordering algorithm out there simple to implement and much better (Mergesort, Quicksort, java.util.Arrays.sort(int[]), etc), you take just the one that is considered to be the standard example of a bad algorithm?

  • I ran the code and saw no problem. The table is being displayed normally.

  • Victor, we were given several topics and this was drawn for us. We are obliged to use it. And I didn’t put the code, because there are several classes and packages at inheritance levels, and you better see this. You understand?

  • Diego. Regarding the adaptive container. I hadn’t thought of it, but in fact the jpanel cuts the table when it’s big. I’ll check that too. The code compiles normal. The problem is that a table is being generated (which is done in Abstracttablemodel) outside the swing window I created. So there are two tables there. I need the new table to take the old one’s place.

Show 2 more comments

1 answer

3


In the builder TelaRegistrar(), just below initComponents(), change as below:

public TelaRegistrar() {
        this.funcoes = new ArrayList<>();
//        this.tela = new ListaFuncoesView(funcoes);
//        tela.setVisible(true);

        initComponents();

        FuncaoModeloTabela mod = new FuncaoModeloTabela(funcoes);
        tblReg.setModel(mod);

}

How you created your own TableModel with class Tabela, just pass the class FuncaoModeloTabela(which seems to complement the class Tabela by extending it) through the method suaTable.setModel(TableModel dataModel).

The class ListaFuncoesView becomes unnecessary with this change, since its function was only to display the table on a part screen.

Another important tip is to always add one JTable in a JScrollPane, so the header of your table will be displayed correctly and, if it has many rows, the container will adjust the vertical scroll automatically.

  • Ok. I made the changes. I deleted Jpanel and put Jtable right into Jscrollpane. It worked perfectly. Thanks. = D Now just one more problem: when I press insert, the table is not updated with the line I put.

  • @Iagomello if the answer answered you, you can mark as accepted by clicking on v, will serve as reference for others with similar problems :)

  • My first post here. hehe Was marked. How do I solve the line insertion problem ?

  • @Iagomello good, this is already another different doubt and would lack another question (or a quick search here you find answers already ready). One of them is you add an empty line, as can be seen here or add a method addRow on your tablemodel, which receives an object of the type the table works. If that’s not quite what you need, then you need to ask another question by adding a [mcve].

  • Thanks. I will check the links and try to be clearer on a next. Hugs.

Browser other questions tagged

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