uitable autofill without cursor jumping to cell (1,1)

조회 수: 3 (최근 30일)
Mikkel Ibsen
Mikkel Ibsen 2018년 5월 15일
댓글: Mikkel Ibsen 2018년 5월 18일
Hi
I've made a gui where I have a uitable that should take the users input an paste it into another cell, for example:
What is in cell(1,2) should be pasted into cell(2,1), and cell(2,2) pasted into cell(3,1) and so on.
I've used this answer to write my code.
function uitable1_CellEditCallback(hObject, eventdata, handles)
table = get(handles.uitable1,'data');
Depth_data = table(:,2);
for h = 1:size(table,1)-1
table(h+1,1) = Depth_data(h);
end
set(handles.uitable1,'data',table);
It does what it is supposed to do, but this is where I have an irritating error, when I enter values the cursor or tab jumps to cell(1,1), so I cant just press enter and it jumps to the next cell, how do I fix this? Is there a way to store where the cursor is and then make it jump back to that cell or the next instead of jumping to cell(1,1) all the time?
  댓글 수: 2
Jan
Jan 2018년 5월 15일
편집: Jan 2018년 5월 15일
I do not understand the logic behind: (1,2) -> (2,1), (2,2) -> (3,1). What exactly does "and so on" mean?
A shorter and simpler code without a loop:
s = size(table,1);
table(2:s, 1) = table(1:s-1, 2);
Mikkel Ibsen
Mikkel Ibsen 2018년 5월 15일
What I'm trying to build is a program that uses layer depths. So the user only enters the end depth of the layers, where the program den automaticity shows the user that the previous layers end depth, is also the same as the new layers starting depth.
When I say and so on, is because the matrix could have 1 to 100 rows, where it should do the same thing, cell(1,2) = cell(2,1) ; cell(2,2) = cell(3,1) ; cell(3,2) = cell(4,1)... and so on..
I just want a code where when you enter a number in cell(1,2) the number also shows in cell(2,1) and where the cursor then doesnt jump to cell(1,1) because you "refreshed" the table.

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2018년 5월 15일
편집: Jan 2018년 5월 18일
[EDITED] Code suggested in this thread:
jUIScrollPane = findjobj(handles.uitableHandle);
jUITable = jUIScrollPane.getViewport.getView;
jUITable.changeSelection(row-1, col-1, false, false);
  댓글 수: 5
Jan
Jan 2018년 5월 18일
Is it worth to discuss, if there should be a way, when there is none? Selecting a cell programmatically works using the underlying Java methods and there is no officially supported method to do this in plain Matlab. I think, this code is easy enough to be used - see [EDITED] in my answer.
Be careful with the technical terms:
In the handle (eventdata) i have the "cell"
EventData is a struct. Although handles is a struct also, EventData is not a handle in any way.
Mikkel Ibsen
Mikkel Ibsen 2018년 5월 18일
Hi Jan
You were right, I made it work using your commands, and now I can even make different codes to force the "cursor" to jump to the next cell automatically. Thx

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by