integrating a Pop-Up Menu into a column of a uitable, is this even possible? If yes how?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tobias Wzl
am 16 Okt. 2017
Kommentiert: Tobias Wzl
am 19 Okt. 2017
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 Kommentare
Jan
am 16 Okt. 2017
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?
Akzeptierte Antwort
Jan
am 16 Okt. 2017
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 Kommentare
Walter Roberson
am 16 Okt. 2017
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.
Weitere Antworten (1)
Walter Roberson
am 16 Okt. 2017
Set the ColumnFormat of the table; https://www.mathworks.com/help/matlab/ref/matlab.ui.control.table-properties.html#property_d119e1107507
"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 Kommentare
Walter Roberson
am 19 Okt. 2017
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.
Siehe auch
Kategorien
Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!