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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:30:46+00:00 2026-05-25T16:30:46+00:00

I created a JTable with a table model . Now based on an input

  • 0

I created a JTable with a table model . Now based on an input which i have, i want to make one column into a particular data Type. How do i do this?

import java.awt.GridLayout;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.AbstractTableModel;

public class MyTableModelTwo extends AbstractTableModel {

    private static final long serialVersionUID = 1L;
    private Object[][] data;
    private String[] columnNames;

    public MyTableModelTwo(Object[][] data) {
        this.data = data;
    }

    @Override
    public int getRowCount() {
        return data.length;
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        return data[rowIndex][columnIndex];
    }

    @Override
    public Class<?> getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

    @Override
    public boolean isCellEditable(int rowIndes, int columnIndex) {
        return true;
    }

    @Override
    public String getColumnName(int index) {
        return columnNames[index];
    }

    @Override
    public void setValueAt(Object value, int rowIndex, int columnIndex) {
        data[rowIndex][columnIndex] = value;
        fireTableCellUpdated(rowIndex, columnIndex);
    }

    public MyTableModelTwo(String[] columnNames, Object[][] data) {
        this.columnNames = columnNames;
        this.data = data;
    }
}

class MyTableTwo extends JPanel implements TableModelListener {

    private static final long serialVersionUID = 1L;
    private JTable table;
    private Object[][] data;
    private JTextField t;

    public MyTableTwo(int noElements, String[] columnNames) {
        data = new Object[noElements][columnNames.length];
        t = new JTextField();
        MyTableModelTwo m = new MyTableModelTwo(columnNames, data);
        table = new JTable(m);
        table.getModel().addTableModelListener(this);
        setLayout(new GridLayout(1, 0));
        JScrollPane scrollPane = new JScrollPane(table);
        add(scrollPane);
    }

    @Override
    public void tableChanged(TableModelEvent e) {
    }

    public JTextField returnT6() {
        return t;
    }
}
  • 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-05-25T16:30:46+00:00Added an answer on May 25, 2026 at 4:30 pm

    overide public Class getColumnClass(int column) {…

    please my question, why do you needed there AbstractModel, for why reasons, really what do you want to restict/mofify/change/override, ( you can prety ignore this == be sure that not really not good way to start to playing with anything for JTable based on AbstractTableModel ), however … consider using DefalutTableModel rather than AbstractTableModel

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Java Swing I have created a JTable which uses a table model class
How do I obtain the user's edit input on a custom model JTable created
Hi I have created a Jtable and can get it to show on my
I created a program using dev-cpp and wxwidgets which solves a puzzle. The user
I created a wcf service based on ServiceHostFactory, and i'm hosting it in IIS6.
I have a tree and a table on my panel, when I click the
I would like to create a table with the constructor method JTable(TableModel). What exact
In the below image I am trying to achieve the following.I have a table
I created a GridView in code with a DataTable as its data source which
Diagrams created with Microsoft SQL Server Management Studio have their default schema set to

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.