12031

Uitable over whole window width

Question:

I would like to programmatically (or in GUIDE) fix the <a href="/questions/tagged/matlab-uitable" class="post-tag" title="show questions tagged 'matlab-uitable'" rel="nofollow">matlab-uitable</a> to be the whole width of the panel on initialisation. How can I do this?

All I've managed is to change the size in pixels of single columns. I would like the uitable to be 100% the width of the page at that time. When my window is in minimized form the GUI looks fine, but when I maximize it, the uitable is only about half the width of the page. (The uitable's height is not that of the whole panel though, around 1/2 of the whole page)

The GUI is written in <a href="/questions/tagged/matlab-guide" class="post-tag" title="show questions tagged 'matlab-guide'" rel="nofollow">matlab-guide</a>.

This is the code that I am trying right now:

data = populateTable; parentPosition = get(handles.uipanel4, 'position'); uitablePosition = [x y parentPosition(3)-2 parentPosition(4)-2]; set(handles.uitable, 'Position', uitablePosition); set(handles.uitable, 'Visible', 'on'); set(handles.uitable, 'Data',data, 'ColumnFormat',{'numeric'});

Answer1:

A possible solution could be to set both the position of the figure and of the table to normalized, then to set the position of the table to [0 0 1 1]

f = figure set(f,'unit','normalized') set(f,'position',[0.1 0.1 0.5 0.5]) data = rand(13); for i=1:length(data) col_names{i}=['Col. # ' int2str(i)]; end for i=1:length(data) row_names{i}=['Row. # ' int2str(i)]; end t = uitable(f, 'Data', data,'unit','normalized', ... 'Position', [0 0 1 1],'columnname',col_names, ... 'rowname',row_names);

Answer2:

You need to set the uitable's <strong><em>position</em></strong> property when you initialize it.

First, get the position of the uitable's parent object. That could be a uipanel or a figure. Assume hParent is a handle to the uitable's parent.

parentPosition = get(hParent, 'position');

Then, create your position vector for the new uitable, and use the parent's width and height. You might want to subtract a few pixels for padding. I'll subtract two pixels here.

uitablePosition = [x y parentPosition(3)-2 parentPosition (4)-2];

You can probably set x and y to 1 or 2 as well, depending on where the table is positioned.

uitable( ... 'units','pixels','position', uitablePosition )

You can implement the same idea in your figure's resize function.

Recommend

  • Can jQuery click events be unbound or reset?
  • Runtime-error in wpf with Window.AllowsTransparent set to true
  • parfor loop won't work with IF statement in MATLAB
  • Add Horizontal Scrollbar for Panel
  • How do I repaint a form after it was restored from a minimized state?
  • How to Stop Gmail from maximizing an iFrame?
  • triangle points around a point
  • Remove Ribbon from Excel
  • How to maximize the goal in prolog?
  • Which video formats to use for Java ME in mobile phones?
  • How to use Exception Handling in Selenium Webdriver?
  • Launching a new command window from Golang in Windows
  • Can't access Tomcat 7 Manager app when running from Eclipse
  • Graceful pod termination
  • Hide buttons on title bar in Java
  • iOS Cordova first plugin - plugin.xml to inject a feature
  • Exception gevent.hub.LoopExit: LoopExit('This operation would block forever',)
  • JSR-330 support in Picocontainer : @Inject … @Named(\"xxx)
  • Can I programmatically choose the Android layout folder?
  • D3 get axis values on zoom event
  • Insert new calendar with SyncAdapter- Calendar API Android
  • Ensure fsync did its job
  • OpenGL 3.3 on Mac OSX El Capitan with LWJGL
  • If I include Java 8 in my Android app does that affect which devices it will work on?
  • Sony Xperia Z Tablet not found by adb
  • How to recover from a Spring Social ExpiredAuthorizationException
  • How to set/get protobuf's extension field in Go?
  • How to show dropdown in excel using jrxml (jasper api)?
  • How can I estimate amount of memory left with calling System.gc()?
  • Confusion with PayPal's monthly billing cycle
  • Acquiring multiple attributes from .xml file in c#
  • Hits per day in Google Big Query
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • embed rChart in Markdown
  • How can I remove ASP.NET Designer.cs files?
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can i traverse a binary tree from right to left in java?
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal