MATLAB Answers

0

integrating a Pop-Up Menu into a column of a uitable, is this even possible? If yes how?

Asked by Tobias Wzl on 16 Oct 2017
Latest activity Commented on by Tobias Wzl on 19 Oct 2017
Accepted Answer by Jan
Hello everyone,
I'm desperately searching for some help/solutions for my code. I want to have a pop up menu in every row of the column P_i-transient.
I can't figure out how it works or if it even works. I would be very happy if someone could help me, because it is quite urgent...
Thank you :)
Code:
% --- FIGURE -------------------------------------
handles.figure1 = figure( ...
'Tag', 'figure1', ...
'Units', 'characters', ...
'Position', [102.8 24.2307692307692 126.8 33], ...
'Name', 'Parameter', ...
'MenuBar', 'none', ...
'NumberTitle', 'off', ...
'Color', [0.941 0.941 0.941]);
% --- UITABLE -------------------------------------
% Initialize empty string for components of the Data
Data=cell(16,5);
for i = 1:numel(Data)
Data{i} = '';
end
handles.uitable1 = uitable( ...
'Parent', handles.figure1, ...
'Tag', 'uitable1', ...
'UserData', zeros(1,0), ...
'Units', 'characters', ...
'Position', [12.2 8 85.6 21], ...
'BackgroundColor', [1 1 1;0.961 0.961 0.961], ...
'ColumnEditable', [true,true,true,true,true], ...
'ColumnFormat', {'char','char','char','char','char'}, ...
'ColumnName',{'ID','<html>P<sub>i</sub> -stationary<br>[W]','<html>P<sub>i</sub> -transient<br>[W/t]','<html>&Omega','V'}, ... % '<html>P<sub>i</sup></html>[W]'für griechische Buchstaben in einer Column <HTML>&Buchstabe
'ColumnWidth', {'auto','auto','auto','auto','auto'}, ...
'Data',Data); % add the "string" Data

  2 Comments

If you claim, that your problem is "urgent" - more urgent then other questions?! - take the time to explain your problem clearly. What does "every row of the column P_i-transient" mean?
I didn't mean that I wanted to be solved right now. The "urgent" is just because I'm pretty desperate to find a solution....
by every row of P_i-Transient, I meant every single cell of the column P_i-Transient.

Sign in to comment.

2 Answers

Answer by Jan
on 16 Oct 2017
 Accepted Answer

If you want a context menu for a uitable: There is none. You could create one manually with Java tricks to determine which cell the mouse is over. But this will be unstable. Try to solve the problem with another method.

  2 Comments

I don't want to use Java, because I never learned how to use java, so this probably will not be an Option but thank you :)
If my answer pointing to the appropriate part of the documentation was not what you were looking for, then you are going to have to explain more fully what you want.
For example if you need to have a different pop-up menu for ever row, then you will need to use the context menu approach, or you will need to use WindowButtonMotionFcn to detect where you have moved your cursor and pop something up if you pass through an appropriate space, or you will need to use java.
But if you need the same pop-up at every row, then the feature is already built-in and I already pointed to how to do it.

Sign in to comment.


Answer by Walter Roberson
on 16 Oct 2017

"A 1-by-n cell array of character vectors, such as {'one' 'two' 'three'}
Display a pop-up menu.
To edit a cell, the user selects an item from the pop-up menu. MATLAB sets the corresponding Data property array value to the selected menu item. The ColumnEditable property value must be true to allow users to select items in the pop-up menu."
Note: this would require that the list of entries be the same for every row in the column.

  15 Comments

Tobias Wzl 2017 年 10 月 19 日
function uitable1_CellSelectionCallback(hObject, eventdata)
datatable_row = eventdata.Indices(1);
datatable_col = eventdata.Indices(2);
% Accept clicks on 3rd columns only:
if datatable_col ~= 3
return;
end
Columndata = get(hObject,'Data');
[FileName,PathName] = uigetfile({'*.txt'; '*.csv'},'Select the configuration');
fidi = fopen( FileName );
data = textscan(fidi, '%f%f', 'Delimiter',',');
if strcmp(Columndata(1,1),'User Defined')
FilePath = fullfile(PathName,FileName);
if isequal(FileName,0)
return
end
[pathstr, name, ext] = fileparts(FilePath);
ParameterList{end+1} = name;
set(uitable1,'ColumnFormat',{ParameterList});
end
end
Solved it :)
Next thing i need to solve is to import a textfile into a cell ... does this work with the importdata-command or how does this work?
I almost never use importdata() myself. I use xlsread() or readtable() or load() for really simple files, or textscan(). It is also not uncommon for me to fileread() the entire file at once as a character string and process it, if the file is a bit more complicated.
Tobias Wzl 2017 年 10 月 19 日
so for my simple txt or csv files I'll use texscan- or load-command, because they just include two columns with several rows.
the title of the files will we variable, so why does the code above not work for me? and how can I load the file into a specific column and still be variable about the row of the column?

Sign in to comment.