AddColumn() make removed column visible again. Pls help. :)

I have a JTable which I need to remove and add column.
// declaration of table and tablemodel
DefaultTableModel tableMod = new DefaultTableModel (data, col);
// data is Object[][] type, col is String[] type
myTable = new JTable(defaultTableModel );
DefaultTableColumnModel columnMod = (DefaultTableColumnModel)myTable.getColumnModel();
My remove column code is :
columnMod.removeColumn(columnMod.getColumn(1));
My add column code is :
tableMod.addColumn("three");
My problem is : say my table has 2 columns initially
"one" "two"
after removeColumn(), the column will disappear from the JTable. like this
"one"
but when I addColumn() later, the removed column will appear again. like this
"one" "two" "three"
I think the problem is DefaultTableColumnModel is used to removeColumn but DefaultTableModel is used to addColumn, resulted in some kind of discrepancy, how to go about this? I know I can do perform addColumn() and removeColumn() on JTable, something like :
remove -
myTable.removeColumn(myTable.getColumnModel().getColumn( myTable.getSelectedColumn() ) );
add -
addedColumn = new TableColumn()
myTable.addColumn(addedColumn);
But when I do this addedColumn has a modelIndex of 0 , and anychanges to addedColumn will be reflected on first column(because modelIndex is 0) as well...which is what I don't want.
Hope I'm making sense, any help appreciated.

Ok, so heres my gripe with actually removing a column from a JTable : A JTable rebuilds its entire column model when it gets certain events (e.g. if the table model calls fireTableStructureChanged). This makes it unreliable to remove columns from the table by the method you give (though im not saying it cant be done, feel free to pursue that avenue if you like). Im just saying a more reliable way to do it is to have you own table model that knows exactly what the columns are to be in the JTable at any time. This way if the JTable rebuilds it column model it wont remake a column you removed.
So heres the basics of removing and adding a column by changing the table model :
A table model (derived from AbstractTableModel) needs to have three functions:
public int getRowCount();
public int getColumnCount();
public Object getValueAt(int row, int column);So if you're at a time when you only want one column, getColumnCount() should return 1. If you want to say add two columns, then have getColumnCount() return 3. You would then also need to change what gets returned by getValueAt() so that it tells what is in the three columns appropriately. Also, whenever the number of columns is changed, you would need to fireTableStructureChanged(), to let the table know to rebuild it column model, with or without the columns you want added/removed.
That is exactly what is done in the other post. I don't mean to not directly answer your question, i just don't think that removing and adding columns like that is how JTable is meant to be used, in MVC architechure. I dont really have any information about adding and removing columns because I've never even attempted to change a table that way. All i can say to that is that you have to figure out how JTable works, which I would try putting tons of System.out() calls telling me exactly what the column model looks like after certain changes(it indexes, etc..).
Well i hope this helps in some small way...
Josh

Similar Messages

  • How do I delete my old iMessage email and change to my current one, that Im using when I buy apps and so on. The old one wont go away when I turn iMessage on and of again. pls help

    How do I delete my old iMessage email and change to my current one, that Im using when I buy apps and so on. The old one wont go away when I turn iMessage on and of again. pls help
    Anyone had the same?

    How do I delete my old iMessage email and change to my current one, that Im using when I buy apps and so on. The old one wont go away when I turn iMessage on and of again. pls help
    Anyone had the same?

  • I've used firefox for a month now but recently if I type on facebook the quick find search bar pops out. Even if I press Esc, when i type on facebook again the quick find bar pops out again. pls help..

    I've used firefox for a month now but recently if I type on facebook the quick find search bar pops out. Even if I press Esc, when i type on facebook again the quick find bar pops out again. pls help..
    even when i click the register on the top right of mozilla it wont allow me to.

    I've used firefox for a month now but recently if I type on facebook the quick find search bar pops out. Even if I press Esc, when i type on facebook again the quick find bar pops out again. pls help..
    even when i click the register on the top right of mozilla it wont allow me to.

  • Make a column visible false?

    Hi ppl
    How do I make column visible false? Tried all kind things without any luck?

    Hi all,
    hmmm...
    To remove a Column you only have to save the removed column into a list. When you want to see the column again, only add it to the TableColumnModel.
    For example:
    public YourTable extends JTable{
      private Hashmap deletedColumns;
      public void removeColumn(Object columnIdentifier){
        TableColumnModel columnModel = getColumnModel();
        int index = columnModel.getColumnIndex(columnIdentifier);
        TableColumn column = columnModel.getColumn(index);
        if(deletedColumns == null)
          deletedColumns = new Hashtable();
        deletedColumns.put(columnIdentifier, column );
        columnModel.removeColumn(column);
      public void addColumn(Object columnIdentifier){
        TableColumnModel columnModel = getColumnModel();
        TableColumn column = (TableColumn )deletedColumns.remove(columnIdentifier);
        if(column != null)
          columnModel.addColumn(column);
    }NOTE: I didnt compile the code, but this is the way to do it.
    Take care, because the default models takes String as identifiers for the headers. That isnt right, because all Objects wich have a implemetation of the "toString" will be returned as a String...

  • Remove Column in Standard Search Help(SAKO)

    Hi Experts,
    I have a requirement in that i have to hide some column in SAKO search help i tried all the posibilities in search help exits
    but couldn't find any way to remove its just going from header selection in search help pop up (input field n its lable)
    but column not get removed.
    kindly suggest me the way.
    ENHANCEMENT 1  ZFI_NOR_ENH_SAKO.    "active version
    * Execution Criteria : On F4 Help                                      *
    * MODIFICATION HISTORY:                                                *
    * Correction No.  Name          Date       Description                 *
    * Begin of Insertion WIW ID -KPANDE |<Project ID> 10000265851 |<Date>21-02-2011|<Transport request>
    tables : ZNOR_USERS.
      data : wa_shlp_tab like line of shlp_tab.
      data : wa_interface like line of shlp_tab-interface.
      data : wa_fielddescr like line of shlp_tab-fielddescr.
      data : wa_fieldprop like line of shlp_tab-fieldprop.
    * Check whehter the Logon User is a NOR Users
    select single * from ZNOR_USERS where NOR_WIW_ID = sy-uname.
      if sy-subrc is initial.
        if callcontrol-step = 'SELONE'.
          if sy-subrc is initial.
         READ TABLE SHLP_TAB INTO WA_SHLP_TAB WITH KEY SHLPNAME = 'GL_ACCT_CA_TEXT'.
         IF SY-SUBRC IS INITIAL.
             LOOP AT WA_SHLP_TAB-INTERFACE INTO WA_INTERFACE.
              IF WA_INTERFACE-SHLPFIELD = 'MCOD1'.
              DELETE WA_SHLP_TAB-INTERFACE INDEX SY-TABIX.
              ENDIF.
            ENDLOOP.
             LOOP AT WA_SHLP_TAB-FIELDDESCR INTO WA_FIELDDESCR.
              IF WA_FIELDDESCR-FIELDNAME = 'MCOD1'.
                DELETE WA_SHLP_TAB-FIELDDESCR INDEX SY-TABIX.
              ENDIF.
            ENDLOOP.
                LOOP AT WA_SHLP_TAB-FIELDPROP INTO WA_FIELDPROP.
              IF wA_FIELDPROP-FIELDNAME = 'MCOD1'.
                DELETE WA_SHLP_TAB-FIELDPROP INDEX SY-TABIX.
              ENDIF.
            ENDLOOP.
              MODIFY SHLP_TAB FROM WA_SHLP_TAB INDEX SY-TABIX.
         ENDIF.
        READ TABLE SHLP_TAB INTO WA_SHLP_TAB WITH KEY SHLPNAME = 'GL_ACCT_CC_TEXT'.
         IF SY-SUBRC IS INITIAL.
             LOOP AT WA_SHLP_TAB-INTERFACE INTO WA_INTERFACE.
              IF WA_INTERFACE-SHLPFIELD = 'MCODF'.
              DELETE WA_SHLP_TAB-INTERFACE INDEX SY-TABIX.
              ENDIF.
            ENDLOOP.
             LOOP AT WA_SHLP_TAB-FIELDDESCR INTO WA_FIELDDESCR.
              IF WA_FIELDDESCR-FIELDNAME = 'MCODF'.
                DELETE WA_SHLP_TAB-FIELDDESCR INDEX SY-TABIX.
              ENDIF.
            ENDLOOP.
                LOOP AT WA_SHLP_TAB-FIELDPROP INTO WA_FIELDPROP.
              IF WA_FIELDPROP-FIELDNAME = 'MCODF'.
                DELETE WA_SHLP_TAB-FIELDPROP INDEX SY-TABIX.
              ENDIF.
            ENDLOOP.
             MODIFY SHLP_TAB FROM WA_SHLP_TAB INDEX SY-TABIX.
         ENDIF.
    ENDENHANCEMENT.
    *$*$-End:   (1)---------------------------------------------------------------------------------$*$*
    thnx..
    ketan...

    The seach help exit is to adjust input and output parameters and there selction
    @Dhiraj: Not true (again).
    To the OP, I'm not sure why you would want to remove such a useful function from the screen.  However, you can overtake the selection and display process entirely with a search help exit if that's your desire.  For more information, read the documentation on search help exits.

  • Column constant value pls help

    COL cnt noprint
    COLUMN  cnt NEW_VALUE rowcountI am using this for select query as below
    ROWNUM cnt, COUNT (*) OVER () cntbut issue is when null rows returned.... this rowcount is not initilized.
    while i am usng for trailer record
    SELECT '* Trailer record *' || '|' || &rowcount
      FROM DUALit is giving error as below
    FROM DUAL
    ERROR at line 2:
    ORA-00936: missing expression
    Pls help
    S

    Solomon Yakobson wrote:
    Post EXACT and COMPLETE snippet of SQL*Plus session showing what you did. I can't reproduce it:
    SQL> COLUMN  cnt NEW_VALUE rowcount
    SQL> SELECT COUNT (*) OVER () cnt
    2    FROM DUAL
    3  /Suppose if cnt gives no record then rowcount is null at that time rowcount is not initiliazed.
    >
    >
    >
    >
    SQL> SELECT '* Trailer record *' || '|' || &rowcount
    2 FROM DUAL
    3 /
    old 1: SELECT '* Trailer record *' || '|' || &rowcount
    new 1: SELECT '* Trailer record *' || '|' || Missing expression this was my error
    >
    '*TRAILERRECORD*'||'
    * Trailer record *|1>
    SQL>
    SY.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to make all columns visible in an interactive report by default

    Hello All,
    I have an interactive report with the first column is visible and the rest are hidden by default. Is there any way that i can make them all visible by default so the users do not have to go into actions to display them in report?
    Thank you
    Sezer

    Login as developer > run the interactive report > actions > select all columns you want
    Now got to actions > save > default > primary > apply
    http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21674/ir_using.htm#CHDFDFJA

  • Lost a shortcut for one of my apps but the app is on my phone when i go into the app store under purchased how do i create a shortcut again, pls help iphone 4

    lost a shortcut for one of my apps but it shows up in the app store as purchased how do I get the shortcut back, pls help iphone 4

    Hi newyorker2014,
    I apologize, I'm a bit unclear on the exact nature of your issue. If you are no longer seeing the app in question on your iPhone, but it is showing as purchased on the App Store, you should be able to redownload it directly. You may find the following article helpful:
    Download past purchases
    http://support.apple.com/kb/ht2519
    Regards,
    - Brenden

  • Tax Calulator applet again pls help urgent

    why isn't it possible to pass a string and a double into GetResult below, i get a compilation error and right now i dunno how to proceed. GetRelief is supposed to calculate "relief" from textfields i/p and GetResult is suppose to calculate the "result" (minus "relief" from GetRelief). And is it the correct way to create an object as in calc = new Calculate(); below................any help would be greatly appreciated...
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    public class TaxCal extends Applet implements ActionListener {
         private TextField income, age, child, parent, course, maid, pay;
         private Button b2, b3;
         private Calculate calc;
         public void init() {
                   setBackground(Color.lightGray);
                   /* Create the input boxes, and make sure that the background
                   color is white. (On some platforms, it is automatically.) */
                   income = new TextField(10);
                   Panel incomePanel = new Panel();
                   incomePanel.setLayout(new BorderLayout(2,2));
                   incomePanel.add( new Label("Input your annual income"), BorderLayout.WEST );
              incomePanel.add(income, BorderLayout.CENTER);
                   age = new TextField(2);
                   Panel agePanel = new Panel();
                   agePanel.setLayout(new BorderLayout(2,2));
                   agePanel.add( new Label("Input your age"), BorderLayout.WEST );
                   agePanel.add(age, BorderLayout.CENTER);
                   child = new TextField(2);
                   Panel childPanel = new Panel();
                   childPanel.setLayout(new BorderLayout(2,2));
                   childPanel.add( new Label("Number of children"), BorderLayout.WEST );
                   childPanel.add(child, BorderLayout.CENTER);
                   parent = new TextField(1);
                   Panel parentPanel = new Panel();
                   parentPanel.setLayout(new BorderLayout(2,2));
                   parentPanel.add( new Label("Number of parent that live with you"), BorderLayout.WEST );
                   parentPanel.add(parent, BorderLayout.CENTER);
                   course = new TextField(5);
                   Panel coursePanel = new Panel();
                   coursePanel.setLayout(new BorderLayout(2,2));
                   coursePanel.add( new Label("Course fee"), BorderLayout.WEST );
                   coursePanel.add(course, BorderLayout.CENTER);
                   maid = new TextField(5);
                   Panel maidPanel = new Panel();
                   maidPanel.setLayout(new BorderLayout(2,2));
                   maidPanel.add( new Label("Maid levy paid"), BorderLayout.WEST );
                   maidPanel.add(maid, BorderLayout.CENTER);
                   pay = new TextField(10);
                   pay.setEditable(false);
                   Panel payPanel = new Panel();
                   payPanel.setLayout(new BorderLayout(2,2));
                   payPanel.add( new Label("Please pay"), BorderLayout.WEST );
                   payPanel.add(pay, BorderLayout.CENTER);
                   Panel buttonPanel = new Panel();
                   buttonPanel.setLayout(new GridLayout(1,3));
                   Button b2 = new Button("Reset");
                   b2.addActionListener(this);     // register listener
                   buttonPanel.add(b2);
                   Button b3 = new Button("Calculate");
                   b3.addActionListener(this);     // register listener
                   buttonPanel.add(b3);
                   /* Set up the layout for the applet, using a GridLayout,
              and add all the components that have been created. */
              setLayout(new GridLayout(8,2));
                   add(incomePanel);
                   add(agePanel);
                   add(childPanel);
                   add(parentPanel);
              add(coursePanel);
              add(maidPanel);
              add(payPanel);
              add(buttonPanel);
              /* Try to give the input focus to xInput, which is
              the natural place for the user to start. */
              income.requestFocus();
              } // end init()
         public TaxCal() {
         calc = new Calculate();
         public Insets getInsets() {
    // Leave some space around the borders of the applet.
         return new Insets(2,2,2,2);
         // event handler for ActionEvent
         public void actionPerformed (ActionEvent e) {
              String s = e.getActionCommand();
              if (s.equals("Calculate"))
                   double relief = calc.GetRelief(age.getText(), child.getText(), parent.getText(), course.getText(), maid.getText());
                   double result = calc.GetResult(income.getText(), relief);
                   pay.setText(Double.toString(relief));
              else
                   income.setText("");
                   age.setText("");
                   child.setText("");
                   parent.setText("");
                   course.setText("");
                   maid.setText("");
                   pay.setText("");
    }     // end actionPerformed()
    public class Calculate
    private double result;
    private double incomeTotal;
    private double ageTotal;
    private double childTotal;
    private double parentTotal;
    private double courseTotal;
    private double maidTotal;
    private double relief;
    public Calculate()
    relief = 0.0;
    result = 0.0;
    incomeTotal = 0;
    ageTotal = 0;
    childTotal = 0;
    parentTotal = 0;
    courseTotal = 0;
    maidTotal = 0;
    public double GetResult(String theincome, Double therelief)
         incomeTotal = Double.parseDouble(theincome);
         relief = therelief;
         incomeTotal =- relief;
         if (incomeTotal <= 7500)
         result = incomeTotal * .02;
         else if (incomeTotal > 7500 && incomeTotal <= 20000)
         result = 150 + ((incomeTotal - 7500) * .05);
         else if (incomeTotal > 20000 && incomeTotal <= 35000)
         result = ((incomeTotal - 20000) * .08) + 775;
         else if (incomeTotal> 35000 && incomeTotal <= 50000)
         result = ((incomeTotal - 35000) * .12) + 1975;
         else if (incomeTotal > 50000 && incomeTotal <= 75000)
         result = ((incomeTotal - 50000) * .16) + 3775;
         else if (incomeTotal > 75000 && incomeTotal <= 100000)
         result = ((incomeTotal - 75000) * .2) + 7775;
         else if (incomeTotal > 100000 && incomeTotal <= 150000)
         result = ((incomeTotal - 100000) * .22) + 12775;
         else if (incomeTotal > 150000 && incomeTotal <= 200000)
         result = ((incomeTotal - 150000) * .23) + 23775;
         else if (incomeTotal > 200000 && incomeTotal <= 400000)
         result = ((incomeTotal - 200000) * .26) + 35275;
         else if (incomeTotal > 400000)
         result = ((incomeTotal - 400000) * .28) + 87275;
         return result;
    public double GetRelief(String theage, String thechild, String theparent, String thecourse, String themaid)
         ageTotal = Double.parseDouble(theage);
         parentTotal = Double.parseDouble(theparent);
         maidTotal = Double.parseDouble(themaid);
         childTotal = Double.parseDouble(thechild);
         courseTotal = Double.parseDouble(thecourse);
                             //determine age relief
                             if(ageTotal<55)
                             relief += 3000;
                             else if(ageTotal>=55 && ageTotal<= 59)
                             relief += 8000;
                             else
                             relief += 10000;
                             //determine children relief
                             if(childTotal<=3)
                             relief += (childTotal*2000);
                             else if(childTotal>3 && childTotal<6)
                             relief += ((childTotal-3)*500 + 6000);
                             else
                             relief += 0;
                             //determine parent relief
                             if(parentTotal == 1)
                             relief += 3000;
                             else if(parentTotal ==2)
                             relief += 6000;
                             else
                             relief += 0;
                             //determine course subsidy
                             if(courseTotal != 0 ) {
                                  if(courseTotal <= 2500)
                                  relief += courseTotal;
                                  else
                                  relief += 2500;
                             //determine maid levy
                             if(maidTotal != 0) {
                                  if(maidTotal <= 4000)
                                  relief += 2 * maidTotal;
                                  else
                                  relief += 0;
    return relief;
    } // end of class Calculate
    }      // end class TaxCal

    You're probably not getting anything to show up because in your actionPerformed() method, b3 has not been initialized.
    You declare static variables:
    Button b2, b3;
    but then in your init() method, you delare new local variables when you specify:
    Button b2 = new Button(...);
    Button b3 = new Button(...);
    Since you're declaring and initializing the new local variables, you have never set the static variables to any values. Try removing the type declaration for b2 and b3 in your init() method as follows:
    b2 = new Button(...)
    b3 = new Button(...)
    Hope this helps!

  • Got a contacts removing virus... pls help

    how do i remove a virus that makes my contacts just not there... when i go to my contacts, they arre all gone, but when i receive a call, it shows who`s calling?!! how can i get my contact outta my phone. anyone ps help me

    what is option you have selected sim memory or phone memory??
    tongue is too confused on what to speak

  • How can I make my ipad work again please help

    Hi I bought my iPad last year and it's been working fine. Today I was just going through the settings and it said there was a software update for IOS7 so I agreed to have it done, but I had no idea it was going to take so long (would be nice if they gave a heads up). I had to use my ipad for timely purposes so after a couple of minutes and what looked like only 2% complete, I tried to stop it and the only way was to turn off the device (no option to pause or stop!).
    Now when I turned it back on it says I have to sync it to iTunes and won't go to any other screen. I synced it to iTunes (first time since I purchased it and my Cloud's memory has been full for months so I have no backup whatsoever of anything on my ipad - pictures, email etc. When I sync it up to iTunes it says that it detects a systems update in progress and I cannot continue until it is completed, would i like to continue. I thought I guess that's my only option so I said ok, but unlike when I did it wirelessly unsynced to iTunes earlier, now it is giving a warning that it will return my iPad to factory settings and erase anything I have on it when it completes installing the software!! No thank you!!!! Wish I had that warning the first time around, I have a year's worth of information stored on there that I do not want deleted.
    Somebody please help, how can I get my iPad back to how it was before and stop this update nonsense ASAP??? What a way to ruin my Sunday Please help anybody who can.... Thank you. (and I don't see an option to back it up it just goes to the page to update the device in order to do anything else). Surely there must be a way!! Anybody??

    From your description it seems that you have to upgrade to iOS 7 now.
    No one can say what state your iPad is in since you interrupted a very critical process!
    It is perfectly normal that your iPad's contents are erased during the upgrade process.
    All your data will be restored afterwards, if, and only if you have a recent backup of your iPad!
    To restore your backup from iCloud follow these instructions:
    http://support.apple.com/kb/PH12521

  • I forgot the answers to my security questions... and I don't know how to make a rescue email address. pls help!

    how do I make a rescue address? and also how do I reset my security questions?

    You need to ask Apple to reset your security questions; this can be done by clicking here and picking a method, or if your country isn't listed, filling out and submitting this form.
    It isn’t possible to create a rescue email address without supplying two of the answers. They wouldn't be security questions if they could be bypassed without Apple verifying your identity.
    (109040)

  • Nothing i try will make my ipod work. Pls Help

    Hi all,
    I recently bought an 80gb ipod, charged it, worked fine and now its dead. When its connected to an outlet in the wall it turns on and works but it wont charge! Ive also tried connecting it to my computer with the original wire it came with but all it says is "Please wait, Very low battery..." Restarting it (menu + center button) does not work. I have the most recent version of itunes and im very sure i have usb 2.0. Its a brand new ipod, could it be it has a faulty battery?
    Id appreciate any help i can get. Thanks everyone...
    rafi.
    80gb video   Windows XP Pro  

    If it has charged for a few hours and won't stay on when you unplug it you either have a dead battery or the battery has become disconnected. I've had to redo the connections on a few batteries, sometimes their ribbon cables will slip out.

  • Wake sleep button makes search screen appear. Pls help!

    pressing the sleep wake button makes my search screen appear. tried to press home/sleep wake but no luck. reconfigured as new ipad: no luck.
    Any suggestions?
    new ipad, 3rd gen.
    thanks,
    Fred

    solved. do not touch screen when pressing button. say it: noob

  • HT2731 i hav iphone and i restart it and delete all the files inside how can i start again my iphoe it say i need a valid sim with no pin lock to activate it again pls help

    i hav iphone and i restart it and delete all the files inside how can i start it again it say i need a valid sim with no pin lock to activate iphone again

    ICCID unknown is a critical failure, usually caused by hacking or jailbreaking the phone. It can not be fixed. The phone will need to be replaced.

Maybe you are looking for

  • 10.4.8 Server, AFP and ACLs

    Hello all! Before escalating I would like to have others take a look a this and confirm. Setup: - 10.4.8 Server, OD-master - AFP Share: "Test" - Usergroup: standard AFP-Share "Test": - Posix: ralph:standard, 644 - ACE: 0: group:standard allow list,ad

  • Can't print from labtop

    I have OfficeJet 6500A Plus printer, 1 desktop, and 1 labtop.  My printer connects to a router.  I can print from my desktop, but cannot print from labtop.  I can't see the printer from my labtop at all.  Should I install the HP OfficeJet software on

  • Time out error in production server  for alv grid report

    hi. i have developed alv grid report using nested select statments. when i testing in development  server it is giving the output but in production server if i give 4 months then it is showing time out error.please help me out..its urgent. Thanks in

  • Keychain Lockout

    Keychain lost all my passwords. I opened Keychain it was empty. Keychain First Aid encountered unexpected errors because "login.keychain does not exist". I tried creating a New Keychain. This failed. I could not even unlock keychain. Keychain had eff

  • Idoc segment field - maximum length ?

    Hi, what is the maximum of characters in a segment field of an idoc ? regards, Hans