Question

I would like to create visualization of database. It's a full-desktop application, and it looks similar to Excel. When i put into my JTable database visualization 100 rows, each one with 6 columns, the application is crushing down. Is there a better class for such a task? Or some other smarter way?

Thats the way i do it:

import PodklasyInterfejsu.Menu;
import javax.swing.*;
import java.awt.*;

public class OknoGlowne extends JFrame 
{    
    public Okno() 
    {
        // ustawienie rozmiaru okna na 100% 
        JFrame Okno = new JFrame(); 

        Okno.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Okno.setTitle("Archiwum Stomatologiczne");


        Toolkit zestaw = Toolkit.getDefaultToolkit();
        Dimension rozmiarEkranu = zestaw.getScreenSize();
        int wysEkranu = rozmiarEkranu.height;
        int szerEkranu = rozmiarEkranu.width;
        Okno.setSize(szerEkranu, wysEkranu - 60);                              


        Container powZawartosci = getContentPane();

        // Panel Górnego Menu:
        Menu GorneMenu = new Menu();
        Okno.setJMenuBar(GorneMenu);

        // Wizualizacja bazy w tabeli:

        JTable tabela = new JTable(komorki, nazwyKolumn);
        tabela.setAutoCreateRowSorter(true);
        Okno.add(new JScrollPane(tabela), BorderLayout.CENTER);

        Okno.setVisible(true);

    }
        private Object[][] komorki = new Object [10][];
        private String[] nazwyKolumn = {"Nazwisko", "Imię", "Pesel", "Płeć", "Data urodzenia", "Adres", "Kontakt"};
}
Was it helpful?

Solution

One problem in the code above is that your data 2-d Object[10][] array, komorki, doesn't match your column String[] array, nazwyKolumn. You have 7 columns and need 7 as the first array index for your Object array. Consider changing this:

private Object[][] komorki = new Object[10][];
private String[] nazwyKolumn = { "Nazwisko", "Imię", "Pesel", "Płeć",
     "Data urodzenia", "Adres", "Kontakt" };

to this:

// !! private Object[][] komorki = new Object[10][];
private Object[][] komorki = new Object[10][7]; //!!
private String[] nazwyKolumn = { "Nazwisko", "Imię", "Pesel", "Płeć",
     "Data urodzenia", "Adres", "Kontakt" };

for starters.

OTHER TIPS

As mentioned by others: have you tried profiling ? I personally have good experiences with JProfiler.

Although we do not yet know whether the JTable is the actual problem, I had performance problems with JXTables (note: the SwingX version of JTable) in combination with large TableModels where the table would iterate over all elements to determine the column size before painting it.

This was solved by setting a prototype value for each column (using TableColumnExt#setPrototypeValue). I am not sure whether a regular JTable contains this logic as well, but it might be worth a try to replace your JTable by a JXTable and set the prototype.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top