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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:20:04+00:00 2026-06-14T15:20:04+00:00

I have a sample code that we use to dynamic row numbers in Java

  • 0

I have a sample code that we use to dynamic row numbers in Java Swing Table i.e JTable. I new to JavaFX and would like to the same in JavaFX. Is there is any way to set automatic row numbers in JavaFX Table

 class LineNumberTable extends JTable {

            private JTable mainTable;

            public LineNumberTable(JTable table) {
                super();
                mainTable = table;
                setAutoCreateColumnsFromModel(false);
                setModel(mainTable.getModel());
                setAutoscrolls(false);
                addColumn(new TableColumn());
                getColumnModel().getColumn(0).setCellRenderer(mainTable.getTableHeader().getDefaultRenderer());
                getColumnModel().getColumn(0).setPreferredWidth(40);
                setPreferredScrollableViewportSize(getPreferredSize());

            }

            @Override
            public boolean isCellEditable(int row, int col) {
                if (col == uneditableColumn) {
                    return false;
                }
                return bEdit;
            }

            @Override
            public Object getValueAt(int row, int column) {
                return Integer.valueOf(row + 1);
            }

            @Override
            public int getRowHeight(int row) {
                return mainTable.getRowHeight();
            }
        }
  • 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-14T15:20:05+00:00Added an answer on June 14, 2026 at 3:20 pm

    In JavaFX, you use TableColumns with CellFactories and CellValueFactories to populate your TableView.

    The JavaFX tutorials have an article that might get you started.

    In one approach I have used I convert the business objects to display into presentation objects and add all necessary properties (like in your case, the number) to them.

    EDIT: In a second, cleaner approach, you could set your CellFactory to create a TableCell that shows its own index property in TableCell#updateItem(S, boolean):

    public class NumberedCell extends TableCell{
    
      protected void updateItem(Object object, boolean selected){
        setText(String.valueOf(getIndex());
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following sample code and noticed that if I attempt to use
Trying to get comfortable with jQuery and I have encountered some sample code that
I have a bit of sample code that is throwing this warning: main.c: In
I have to create an sample code that connect to a socket server, and
I have a plot (sample code pasted below) that I am trying to add
I have the following code sample that im trying to wrap my head around
So I have a few properties that I'm using in some sample code I'm
I have a simple java code that reads text csv file that contains sentences
I have this simple code that speaks for itself. <script language='javascript"> function check() {}
I am building a PhoneGap/Cordova app and have a simple code that uses http://ricostacruz.com/jquery.transit/

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.