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 8298043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:37:35+00:00 2026-06-08T15:37:35+00:00

I am new to Java Swing and I am trying to create an application.

  • 0

I am new to Java Swing and I am trying to create an application.

I have a MainApplication.java file which extends SingleFrameApplication and where I am creating a JPanel named MainPanel. This MainPanel has an AnimatingSplitPane with VERTICAL_SPLIT named SplitPane.

On the Top of the SplitPane, I am adding another JPanel named MainContainer. On the bottom of the SplitPane, I am adding a JPanel named FormContainer. The MainContainer loads the another class named DataSheetTable (a JPanel having JTable).

Now, when user clicks on the cells of the DataSheetTable, I want to load the form into the FormContainer. I don’t know, how can I achieve this.

For instance, DatasheetTable has Column1, Column2 and Column3. When user clicks on any cell of Column1, I need to show Form1 into the FormContanier. If it clicks on Column2 cell then I need to show Form2 into FormContanier.

Please let me know with some sample code, how can I achieve loading the forms on the fly to FormContainer.

![Thank you in advance.]

Image description for the issue

Here is sample code for App.java

public class App extends SingleFrameApplication {
 @Override protected void startup() {
    configureDefaults();

     View view = getMainView();
     view.setComponent(createMainPanel());

    show(view);
 }

protected JComponent createMainPanel() {
    // Create main panel with demo selection on left and demo/source on right
    mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());


    // Create splitpane on right to hold demo and source code
    splitPane = new AnimatingSplitPane(JSplitPane.VERTICAL_SPLIT);
    mainPanel.add(splitPane, BorderLayout.CENTER);

    // Create panel to contain main panel
    mainContainer = new JPanel();
    splitPane.setTopComponent(mainContainer);

    DataSheetTable dataSheetTable = new DataSheetTable();
    mainContainer.add(dataSheetTable, BorderLayout.CENTER);
    dataSheetTable.start();

    formContainer = new JPanel(new BorderLayout());
    splitPane.setBottomComponent(formContainer);
    formContainer.add(new OrganizationForm());

    return mainPanel;
  }
} 

Here is sample code for DataSheetTable.java file

public class DataSheetTable extends JPanel {

    ........
     controlPanel = createControlPanel();
     add(controlPanel, BorderLayout.NORTH);


    routingTable = new JTable(routingModel);

   .........

}
  • 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-08T15:37:37+00:00Added an answer on June 8, 2026 at 3:37 pm

    So here is your code for intercepting events of table cell clicks:

    public class App extends JFrame {
        private DefaultTableModel model = new DefaultTableModel(new Object[][] {
                { "Value1", "Value2", "Value3" }, { "Object1", "Object2", "Object3" } }, new String[] {
                "Column1", "Column2", "Column3" });
        private JTable table = new JTable(model);
        private JPanel bottomPanel;
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    App a = new App();
                    a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    a.setLocationRelativeTo(null);
                    a.setVisible(true);
                }
            });
        }
    
        public App() {
            JSplitPane pane = new JSplitPane();
            pane.setOrientation(SwingConstants.HORIZONTAL);
            pane.setLeftComponent(new JScrollPane(table));
            bottomPanel = new JPanel();
            bottomPanel.add(new JLabel("properties for column will be here"));
            pane.setRightComponent(bottomPanel);
            add(pane);
    
            ListSelectionListener listener = new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent e) {
                    int column = table.getSelectedColumn();
                    int row = table.getSelectedRow();
                    if(row != -1 && column != -1) {
                        bottomPanel.removeAll();
                        //Here you add your components/create appropriate panel
                        //e.g. bottomPanel.add(new PropertiesPanelForValue1(...));
                        bottomPanel.add(new JLabel("User selected column " + column + " and row " + row
                                + " with value: '" + table.getValueAt(row, column) + "'"));
                        bottomPanel.revalidate();
                    }
                }
            };
            table.getSelectionModel().addListSelectionListener(listener);
            table.getColumnModel().getSelectionModel().addListSelectionListener(listener);
    
            pack();
    
            pane.setDividerLocation(0.3);
            setSize();
        }
    
        private void setSize() {
            double widthPart = 0.3;
            double heightPart = 0.5;
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            int width = (int) (screenSize.getWidth() * widthPart);
            int height = (int) (screenSize.getHeight() * heightPart);
            setSize(width, height);
            Dimension windowSize = getSize();
            int x = (int) ((screenSize.getWidth() - windowSize.getWidth()) / 2);
            int y = (int) ((screenSize.getHeight() - windowSize.getHeight()) / 2);
            setLocation(x, y);
        }
    }
    

    EDIT
    Looking at your update: Just add to DataSheetTable constructor reference to your FormContainer:

    formContainer = new JPanel(new BorderLayout());
    splitPane.setBottomComponent(formContainer);
    formContainer.add(new OrganizationForm());
    
    DataSheetTable dataSheetTable = new DataSheetTable(formContainer);
    mainContainer.add(dataSheetTable, BorderLayout.CENTER);
    dataSheetTable.start();
    

    and in DataSheetTable add listener:

    public class DataSheetTable extends JPanel {
    
    public DataSheetTable(final FormContainer formContainer) {
    ........
     controlPanel = createControlPanel();
     add(controlPanel, BorderLayout.NORTH);
    
    
    routingTable = new JTable(routingModel);
    ListSelectionListener listener = new ListSelectionListener() {...};
    routingTable.getSelectionModel().addListSelectionListener(listener);
                  routingTable.getColumnModel().getSelectionModel().addListSelectionListener(listener);
    
    .........
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a SWING application using Java 1.6 and I have a
I am new to Java Swing I want to develop an POS application which
I'm trying to create image from SQLite database in Java Swing application. But it
Hi am new to java and have been trying to create a form for
I am trying to create a custom component using Java AWT or Swing which
I'm new to java.I'm creating a swing based UI. I've created 2 frames, each
I'm new to java so forgive the noob question. I have created a swing
I am using Java Swing to create a JDialog, and i am trying to
I am new to java swing. I have pasted my code below for your
I am creating a Java Application using netBeans and Swing Gui Builder. I am

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.