-1

I have a problem with data, inside the cell in selected tab what contains JTable where i want to do calculations. I made 3 tabs with 3 tables, each cell of my table have integers for tests. I want to select tab with index=1 then try to make easy formula like sum(x+y), its work of course but not for data from index=1 but for lastIndex of my JTabbedPane. Can someone tell me how to solve this problem?

public class TabbedTable extends FormPanel implements ChangeListener{

private JTabbedPane jTabbedPane;
private int spreadCount;
private TaskPane taskPane;
private MultiOptionPane multiOptionPane;
private SpreadSheet[] spreadSheet;

public TabbedTable(String col,String row){
    super(col, row);
    initializePanel();
    initializeTaskPane();
    this.setBorder(BorderFactory.createBevelBorder(1, Colors.MyGray.color().darker(), Colors.MyGray.color().brighter()));


    jTabbedPane.setUI(new TabbedUI());
    jTabbedPane.addChangeListener(this);
    jTabbedPane.setFont(Fonts.Calibri.font());
}


private void initializePanel(){
    this.spreadCount = 3;
    this.createtabbedPane();
}


private void createtabbedPane(){
    jTabbedPane = new JTabbedPane();
    taskPane = new TaskPane();
    spreadSheet = new SpreadSheet[spreadCount];

    for(int i = 0 ; i < spreadCount ; i ++){
        spreadSheet[i]= new SpreadSheet(20,20,i);
        jTabbedPane.addTab(spreadSheet[i].getTitle(), spreadSheet[i].getScrollPane());
    }

    this.addXY(taskPane, 1, 2);
    this.addXY(jTabbedPane, 2, 2);

}

}

screen 3 screen 4

screen 1 screen 2

Class diagram

  • 1
    This seems to be more an issue with the "Spreadsheet" object you use, rather than JTable. Please provide more details about what this class is exactly, as we don't have all the information to determine what is happening. – Gnoupi Apr 09 '15 at 21:53
  • @Gnoupi Spreadsheet is my component based on JTable mvc model. Do i really have to show you the code of this cause it's big also it works fine for one tab no problem with that but if u want to see the code no problem. – Kacper Sobisz Apr 09 '15 at 22:03
  • 1
    You don't have to show everything, but the issue is probably there, as I see nothing particular in the code you copied. The only thing which is making me curious is the integer in parameter of the constructor. Wondering what is it for. Also, check you don't have a static element in your computation code, which would cause you to have the same result on different instances, as it looks like on your screenshots. – Gnoupi Apr 09 '15 at 22:11
  • @Gnoupi problem solved as u said, cause of static element thx ! – Kacper Sobisz Apr 09 '15 at 23:09

1 Answers1

1

For the sake of completeness, I will put my comment as an actual answer.


Nothing wrong appears in the code you show. Ideally, we need to see what is going on in the Spreadsheet class.

From the screenshot though, it seems like you have the same value for both tabs, on the same place. If this is happening every time, it could indicate that you have an issue with static values, since your calls to constructors are well separated. So you should look into that.

Gnoupi
  • 4,715
  • 5
  • 34
  • 50