java - JTable:How to initialize a empty cell(type is int/float...) to allow user to input number in JTable? -


i know there's way initialize empty string cell this:

    object[][] tabledata={                           {""},{""}                          };     string[] columntitle = {"aaa", "bbb"};     jtable jtable= new jtable(tabledata, columntitle); 

  • to avoids empty comments here

    1. i had read oracle tutorial didn't it.
    2. but it's type number(int/float/double), can right-justified , formatted.
    3. object[][] tabledata={{null},{null}}; doesn't satisfy me, because type not number or cannot right-justified , formatted.


    4. for example (mixing possible in jtables , defaulttablesmodels apis, btw based on oracle tutorial - how use tables)

enter image description here

import javax.swing.jframe; import javax.swing.jscrollpane; import javax.swing.jtable; import javax.swing.listselectionmodel; import javax.swing.scrollpaneconstants; import javax.swing.swingconstants; import javax.swing.table.defaulttablecellrenderer; import javax.swing.table.defaulttablemodel;  public class jtablessscce {      private jframe frame = new jframe();     private string[] columnnames = {"nama", "nim", "ip", "hapus baris ke"};     private object[][] data = {         {"igor", null, "1.124.01.125", true},         {"lenka", "b21_002-242", null, true},         {"peter", null, "99.124.01.001", null},         {"zuza", "b12_100-242", null, null},         {"jozo", "bus_011-358", null, false},         {"nora", null, "9.124.01.154", null},         {"xantipa", null, "1.124.01.001", false},};     private defaulttablemodel model = new defaulttablemodel(data, columnnames) {         private static final long serialversionuid = 1l;          @override         public boolean iscelleditable(int row, int column) {             switch (column) {                 case 3: // fourth column editable                     return true;                 default:                     return false;             }         }          @override         public class<?> getcolumnclass(int column) {             switch (column) {                 case 0:                     return string.class;                 case 1:                 case 2:                     return integer.class;                 case 3:                     return boolean.class;                 default:                     return null;             }         }     };     private jtable table = new jtable(model);      public jtablessscce() {         table.setautocreaterowsorter(true);         table.setpreferredscrollableviewportsize(table.getpreferredsize());         table.setfillsviewportheight(true);         table.getselectionmodel().setselectionmode(listselectionmodel.single_selection);         defaulttablecellrenderer stringrenderer                 = (defaulttablecellrenderer) table.getdefaultrenderer(string.class);         stringrenderer.sethorizontalalignment(swingconstants.center);         jscrollpane pane = new jscrollpane(table,                 scrollpaneconstants.vertical_scrollbar_as_needed,                 scrollpaneconstants.horizontal_scrollbar_as_needed);         frame.add(pane);         frame.setdefaultcloseoperation(jframe.exit_on_close);         frame.pack();         frame.setvisible(true);     }      public static void main(string[] arg) {         java.awt.eventqueue.invokelater(new runnable() {             @override             public void run() {                 new jtablessscce();             }         });     } } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -