hi
i am working in project that i have multiple frame so i used with my project static variables but i cannot use these array with my table in another frame too many exception is appered and my frame that cotain the table doesnot apper how can i solve this problem

Dani AI

Generated

Thread summary and practical next steps based on the replies from , , , and .

Common checks and quick fixes (what to verify first)

  • Confirm GUI construction runs on the Event Dispatch Thread (EDT). Swing must be created/updated on the EDT to avoid unpredictable behavior.
  • Make sure the table is actually added to the window (usually inside a JScrollPane) and that the window is packed or sized and setVisible(true) is called.
  • Verify the table data and column metadata are initialized before the table is constructed; mismatched column counts or null arrays can throw exceptions at construction time.
  • If the display frame never appears, look for exceptions thrown during construction; a thrown exception will often prevent the frame from showing. As and suggested, include the exact stack trace when asking for help.

Recommended pattern (use a shared TableModel and update on the EDT)

  • Create and populate a DefaultTableModel (or a custom TableModel) and reuse that single model between components instead of spreading static arrays across frames. This makes updates and sharing deterministic and avoids many lifecycle problems.

Example (create model, populate, build UI on EDT):

final DefaultTableModel model = new DefaultTableModel(new Object[] {"Name","Age"}, 0);
model.addRow(new Object[] {"Alice", 30});

SwingUtilities.invokeLater(new Runnable() {
    public void run() {
        JTable table = new JTable(model);
        JFrame frame = new JFrame("Display");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.getContentPane().add(new JScrollPane(table));
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
});

Design note

  • Prefer a single main window with swapped panels (CardLayout) or pass a data-holder / TableModel object between components instead of multiple top-level frames, echoing 's advice. When asking for further help, include a minimal, complete reproducer and the exact exception stack trace so responders can pinpoint the root cause.

Recommended Answers

All 7 Replies

too many exception is appered

please copy and paste them here if you want help resolving them.

You have several problems that will require you to post some code showing what is happening for anyone to be able to help.

Please wrap your code in code tags using the [CODE} icon above the input box.

if you can instead of passing objects between different frames why don't you just change panels and pass around data object that populate these panels?

here is the code in the displaying frame:

private JTable table=new JTable(ll.row,ll.column)

here is the code of th ll frame for the two array:

public static Object row[][]=new Object[12][12];
public static Object column[]=new Object[12];

What is the posted code supposed to show?
Can you explain why you have posted this code?

lena1990
Can you post your full code at least where these problems arise.Otherwise I could not understand your problem.

hi
i have two frame the first frame(it is named login) has two arrays i defined them as static variables here is the code

public static Object[] [] data =
{ {"Marsha", new Integer(18)},
{"Jan", new Integer(17)},
{"Cindy", new Integer(16)} };
public static String[] colNames = {"First Name","Age"};

now in the second frame(it is named display) i want to call the arrays and put them in the jtable so here is the code:

JTable table1=new JTable(login.data,login.colNames);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.