MATLAB Answers

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

조회 수: 68(최근 30일)
Tobias Wzl
Tobias Wzl 16 Oct 2017
댓글: Tobias Wzl 19 Oct 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 :)
% --- 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
for i = 1:numel(Data)
Data{i} = '';
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

Jan 16 Oct 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?
Tobias Wzl
Tobias Wzl 16 Oct 2017
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.

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

채택된 답변

Jan 16 Oct 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

Tobias Wzl
Tobias Wzl 16 Oct 2017
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 :)
Walter Roberson
Walter Roberson 16 Oct 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.

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

추가 답변(1개)

Walter Roberson
Walter Roberson 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

표시 이전 댓글 수: 12
Tobias Wzl
Tobias Wzl 19 Oct 2017
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
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)
[pathstr, name, ext] = fileparts(FilePath);
ParameterList{end+1} = name;
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?
Walter Roberson
Walter Roberson 19 Oct 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.
Tobias Wzl
Tobias Wzl 19 Oct 2017
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?

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

Community Treasure Hunt

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

Start Hunting!

Translated by