MATLAB GUI tab ordering - matlab

In my current project I have a bunch of edit text boxes in my gui. When I/m in the first text blank and hit the tab key it skips to the third text box, when I hit tab again it goes to the second box. Every time I hit tab it jumps around in this weird order. I found out that the order is dependent on the order of the callback function for each text box. Without going in an copy pasting and changing around the code that gets generated by guide is there a better way to order my text boxes.
So for example when I'm in the box red x and hit tab it takes me to the box red z, than red y than green x then green z. I want to be able to click red x and then using just tab step through and fill out the other blocks. Is it at all possible to re-order?

GUIDE-generated GUI
When using GUIDE, you can simply use the "Tab Order Editor". Get to it using the following menu item:
For this simple GUI, with a single button and two text boxes, you would see the following dialog box:
Then set the tab order by moving UI objects up/down.
Programmatic GUI
To set the tab order programatically, you can use uistack to reorder the handles.
For example, to move a uicontrol "up" one in the order:
uistack(hui,'up',1)
To see the order of the handles to all controls in figure hf:
ch = get(hf,'Children')

Related

enable context menu for specific cell or item in uitable or uilistbox in matlab

I created a uitable (new version using appdesigner) in MATLAB and wanted to support right clicking on cells and showing a cell specific context menu. Much to my surprise there seemed to be no way to support this.
The context menu only seems to trigger with right click on the uitable, but there is no way of knowing which cell was selected (I think, maybe not?). I created a workaround where I left clicked to select a cell, and during that selection I right clicked using a Java Mouse robot to trigger the context menu. This is super ugly but sort of works. Except, if you need to bring up the menu twice on the same cell. Apparently the cell selected callback only fires once for the cell, until a new cell is selected. I tried literally putting two tables in the same spot and upon selecting one toggling to the other, but the memory of cell selection is table specific, so this only worked for two clicks before both tables had been clicked on the same cell, and toggling visibility back to the first resulted in the cell selection callback not firing (since the cell had not changed) . I tried various approaches to try and deselect the cell (disable/enable, visibility change, data change, etc.), but the cell selection callback never changed.
I even tried having duplicate columns, where the goal was to hide a column, where normally columns 1 and 2 would be visible (column 3 out of view due to size), and then on clicking on column 2, column 2 would hide itself (0 width) and column 3 (an exact duplicate) would move into its place, thus seeming to the user like multi-clicking was supported. Unfortunately I can't set the column width to 0 -- or rather, setting it to 0 doesn't completely hide the column. Instead there seems to be some minimal width to the column and the whole thing looked awful.
I wanted to do something similar with a listbox (right click support), but again I couldn't figure out how to identify where I was right clicking. I eventually settled on left clicking on a listbox and using the mouse robot approach to right click to bring up the context menu. Unlike the uitable, it was fairly easy to clear the selection on the listbox (set listbox.Value = {}). However, I strongly dislike the left click instead of right click approach and I'd rather have multiple columns.
Any suggestions would be much appreciated!!!
So I found an approach that is better than using a robot. I had tried this but was missing a critical portion which I will describe below.
Upon selecting a row in the table, the open command can be used to launch a context menu. My problem was that I didn't know where to launch the menu. I tried CurrentPoint for the figure, but it was 0,0 (or in general not valid)
Here's the current documentation for CurrentPoint:
Current point, returned as a two-element vector. The vector contains
the (x, y) coordinates of the mouse pointer, measured from the
lower-left corner of the figure. The values are in units specified by
the Units property.
The coordinates update when you do any of the following:
Press the mouse button within the figure.
Release the mouse button after pressing it within the figure.
Press the mouse button within the figure, and then release it outside
the figure.
Rotate the scroll wheel within the figure.
Move the mouse within the figure (without pressing any buttons),
provided that the WindowButtonMotionFcn property is not empty.
If the figure has a callback that responds to mouse interactions, and
you trigger that callback faster than the system can execute the code,
the coordinates might not reflect the actual location of the pointer.
Instead, they are the location when the callback began execution.
If you use the CurrentPoint property to plot points, the coordinate
values might contain rounding error.
Here's the critical line again:
"Move the mouse within the figure (without pressing any buttons), provided that the WindowButtonMotionFcn property is not empty."
So when a selection of a cell happens, the CurrentPoint is not valid. However, if we simply define a WindowButtonMotionFcn, then it is!
So the general idea is to have a callback for the table when a cell is selected (SelectionChangedFcn) and to set a dummy callback for WindowButtonMotionFcn
The final point is that a context menu can be launched with the open function if you specify a given location to launch it at. This is different from attaching it to an object and having it automatically launch on right click.
Here's some example code. If you comment out the callback for windows motion then the whole thing doesn't work! Unfortunately it is a left click for targeting the cell but at least it avoids the non-sense I was using with a java robot right click.
classdef wtf < handle
properties
h %struct, this was an appdesigner handle
cm %context menu
end
methods
function obj = wtf()
h = struct;
h.UIFigure = uifigure();
h.UITable = uitable(h.UIFigure);
obj.h = h;
obj.h.UITable.CellSelectionCallback = #obj.tableCall;
%obj.h.UITable.SelectionChangedFcn = #obj.tableCall;
%Some data ...
s = struct;
s.a = (1:4)';
s.b = (5:8)';
obj.h.UITable.Data = struct2table(s);
%Our context menu
cm = uicontextmenu(obj.h.UIFigure);
m = uimenu(cm,'Text','Menu1');
obj.cm = cm;
%WTF ... without this we don't get a valid CurrentPoint
obj.h.UIFigure.WindowButtonMotionFcn = #obj.mouseMove;
end
function tableCall(obj,x,y)
%y - event info
%x - impacted object
cp = get (obj.h.UIFigure, 'CurrentPoint');
open(obj.cm,cp(1),cp(2));
selected_cell = y.Indices;
%selected_cell = y.Selection;
x.Selection = []; %allows reselecting same cell without
%needing to select another cell first
%Now we can run something on the context menu
%that targets the selected cell
end
function mouseMove(obj,x,y)
%we could store a point here
end
end
end

How can I add waitbar in the current GUI window MATLAB?

I am having a GUI figure, which contains some buttons, I want to show waitbar on the same GUI window on which buttons are placed, I tried different solutions but in vain. e.g when user clicks on button it starts showing me waitbar on left bottom side of the figure.
You could try to add a java waitbar in your figure.
Put this in the OpeningFcn
PB=javaObjectEDT(javax.swing.JProgressBar);
javacomponent(PB,[10,10,200,20],gcf); %put at bottom part of the current figure
set(handles.output.Children(1),'Tag','first_bar'); %make sure you can find it back
In the callback of any function you can then set the bar to a value between 0 and 100 using this code:
h=findobj(handles.output.Children,'Tag','first_bar');
set(h.JavaPeer,'Value',rand(1)*100)
You can make it visible or invisible just as you would any GUI object in Matlab using
h=findobj(handles.output.Children,'Tag','first_bar');
set(h,'visible','off');
Here you can find details about the JProgressBar . For example using this you get a string with the progress inside the bar.
h=findobj(handles.output.Children,'Tag','first_bar');
set(h.JavaPeer,'StringPainted',1)

Background changes color when hovering

So I have a grid in Zkoss with a certain amount of columns. One the first row I place two labels which fill the first two columns (as expected).
I've written their style so that they don't have change color when you hover the mouse over them however one of the columns label is much bigger than the other and when I hover the mouse over the smaller label the area around which isn't filled by the text goes to white.
ZKFiddle example
I'm going insane around this as I'm simply unable of making that area have the same background as the label.
Like I already said in your duplicated question.
CSS is responsible and you just need to search with developer tools.
This update to your fiddle tooks me 2 min.
The changed thing :
.z-row:hover > .z-row-inner, .z-row:hover > .z-cell {background:red; !important}

how to manage uipanels matlab gui

I have 6 uipanels ,all same size overlapped one over another. I have to add buttons edit text to all the uipanels.but I can edit only 6th uipanel and all others are hidden.how can I make only one uipanel visible at a time so that I can easily add buttons and text to it. I have to add a push button in each panel which when clicked should show succeeding uipanel and hide previous uipanel.
For example,
I have a uipanel1 with a push button.when. I click the push button,it should show uipanel2 and hide uipanel1.
thanks
First of all you have to define yours uipanels as variables. For example, uipanel1 = uipanel(...); uipanel2 = uipanel(...)
So you can access easily to your six uipanel handles and put these handles in your button callback function.
Another solution would be to use the 'Tag' property for the uipanel in order to identify the uipanel. It may be longer but by using the findobj('Tag','uipanel1_tag') function, you can easily find the desired handle.

Way to get a color while transitioning

I thought about the whole transition thing, and also saw while a text's color is being transitioned - it crosses through other tints of colors.
I had a lot of situations when I saw a beautiful color which I wanted, but it was a part of the transition process, and I eventually couldn't accomplish it.
For example, this code:
HTML:
<div id="transition">
ultra super califragilisticexpialidocious
</div>
CSS:
#transition {
color:black;
transition: 1s color;
}
#transition:hover {
color:#f00;
}
A demo: JsBin
You could see the transition shows a maroon color while text is transitioned, and my meaning is, how can I get this special tint of maroon?
Generally, my question is, how can I get a color while it is transitioned? There's a way to pick it?
Thanks in advance
Well, the things we think we like most are often those that are hard to get ;-)
But it's not so hard in this case. The question is whether picking the transitioning color is the best way to get what you want. Wouldn't it be simpler to change the color by hand until it looks best?
This is how to easily change a displayed font color with the Firebug plugin of Firefox:
Open the page with the transition and open the Firebug window.
Select the HTML tab, and then the Style tab of the side panel (if the side panel is closed, open it by clicking on the small arrow in the top right corner).
Click on the button with the mouse pointer in the top left corner of the Firebug window, then click on the div with the transition, thus selecting it.
You may want to disable the transition in the style, by clicking to the left of it.
You may want to display colors in RGB instead of hex (you can toggle back and forth when you want), by clicking on the dropdown button in the Style tab and selecting the mode you want.
You can click on the color value to edit it. Instead of rewriting it, you can click again on a single component (works in hex mode too), and then use the up and down arrow keys. It's almost like having a slider for each component. If you have the whole value selected, the arrow keys change all three components simultaneously.
Chrome is almost identical in operation. You open the Developer Tools with Ctrl-Shift-I, select an element with the magnifier button, and edit its style. You can toggle between hex colors and RGB colors by clicking on the gear-wheel within the Styles window. The difference with Firebug is that you can only modify the single RGB values with the up and down arrow keys when in RGB mode, in hex mode the arrow keys can only change the hex value as whole (i.e., starting from the B channel).
Knowing the numerical values of the endpoint colors of the transition, you can guess the numerical values of the "transition color" you want. The numerical value of each RGB (red, green, blue) component will be an intermediate value between its endpoints, more or less close to one of the two endpoint values.
The browser is free to interpolate by using the algorithm it prefers. The easiest algorithm moves colors along a straight line in the three-dimensional RGB space. Interpolated colors in this case (called linear interpolation in RGB space) are integer approximations of
R = R[0] * (1 - t) + R[1] * t
G = G[0] * (1 - t) + G[1] * t
B = B[0] * (1 - t) + B[1] * t
for t varying from 0 to 1. For t = 0.5 you get the color which is linearly (in RGB) halfway between the two endpoints. The parameter t may be any function of time (in the simplest case it is a linear function, which means that the color moves at constant speed in RGB space between the two endpoints).
As I said, the browser is free to interpolate in a more complicated way, in order to achieve a better visual result. If you really need to see what the browser does, you can slow it down to snail speed (e.g., by editing the transition-duration with Firebug), then grab the screen (e.g., by pressing the "Print Scrn" key), open your favorite image editor, paste the printed screen (often by pressing Ctrl-V), and finally select a fully colored pixel to get the RGB values of your long craved color.
BTW, your test case is particularly easy, because the endpoints are (0,0,0) and (255,0,0), so that the maroon color you are after is almost certainly nothing but a dark red of the kind (x,0,0). You only have one parameter to vary, you can even do it by trial and error with an editor!