SWT桌有固定高度(SWT table with fixed height)
我有一个像这样的简单SWT表,初始高度为60px:
Table table = new Table(parent, SWT.BORDER | SWT.FULL_SELECTION); GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); gd_table.heightHint = 60; table.setLayoutData(gd_table); table.setHeaderVisible(true);
我是以编程方式添加行,当添加新行时,表的高度会增加,与UI的其余部分混乱,有没有办法为表设置固定高度,并且可能在行没有时添加滚动条t适合桌面高度?
I have a simple SWT table like this, with an initial height of 60px:
Table table = new Table(parent, SWT.BORDER | SWT.FULL_SELECTION); GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); gd_table.heightHint = 60; table.setLayoutData(gd_table); table.setHeaderVisible(true);
I'm programmatically adding rows, when a new row is added the height of the table is increased messing with the rest of the UI, is there a way to set a fixed height to the table and maybe adding a scrollbar when the rows doesn't fit the table height?
原文:https://stackoverflow.com/questions/29976690
最满意答案
为什么不跟随作者并使用额外的验证编写自己的扩展方法?
看看这里。 这是
services.Configure<>
的源代码services.Configure<>
方法:namespace Microsoft.Extensions.DependencyInjection { /// <summary> /// Extension methods for adding options services to the DI container. /// </summary> public static class OptionsServiceCollectionExtensions { ... /// <summary> /// Registers an action used to configure a particular type of options. /// </summary> /// <typeparam name="TOptions">The options type to be configured.</typeparam> /// <param name="services">The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> to add the services to.</param> /// <param name="configureOptions">The action used to configure the options.</param> /// <returns>The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> so that additional calls can be chained.</returns> public static IServiceCollection Configure<TOptions>(this IServiceCollection services, Action<TOptions> configureOptions) where TOptions : class { if (services == null) throw new ArgumentNullException("services"); if (configureOptions == null) throw new ArgumentNullException("configureOptions"); services.AddSingleton<IConfigureOptions<TOptions>>((IConfigureOptions<TOptions>) new ConfigureOptions<TOptions>(configureOptions)); return services; } } }
如您所见,
Configure<TOptions>
方法是一种扩展方法。 只需编写自己的ConfigureAndValidate<TOptions>()
说ConfigureAndValidate<TOptions>()
扩展方法,它将在services.AddSingleton...
line之前进行适当的验证。Why not to follow the authors and write your own extension method with additional validation?
Take a look here. This is the source code of
services.Configure<>
method:namespace Microsoft.Extensions.DependencyInjection { /// <summary> /// Extension methods for adding options services to the DI container. /// </summary> public static class OptionsServiceCollectionExtensions { ... /// <summary> /// Registers an action used to configure a particular type of options. /// </summary> /// <typeparam name="TOptions">The options type to be configured.</typeparam> /// <param name="services">The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> to add the services to.</param> /// <param name="configureOptions">The action used to configure the options.</param> /// <returns>The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> so that additional calls can be chained.</returns> public static IServiceCollection Configure<TOptions>(this IServiceCollection services, Action<TOptions> configureOptions) where TOptions : class { if (services == null) throw new ArgumentNullException("services"); if (configureOptions == null) throw new ArgumentNullException("configureOptions"); services.AddSingleton<IConfigureOptions<TOptions>>((IConfigureOptions<TOptions>) new ConfigureOptions<TOptions>(configureOptions)); return services; } } }
As you can see
Configure<TOptions>
method is an extension method. Simply write your own let sayConfigureAndValidate<TOptions>()
extension method which will do proper validation beforeservices.AddSingleton...
line.
相关问答
更多-
mvc core 2.0,如何通过配置使用appSettings.json文件(mvc core 2.0, how to use an appSettings.json file via configuration)[2023-05-29]
是的,ASP.NET Core 2.0改变了配置构建的方式。 您现在需要使用IWebHostBuilder.ConfigureAppConfiguration方法。 将这样的内容添加到Program.cs中的IWebHost创建中: .ConfigureAppConfiguration((builderContext, config) => { IHostingEnvironment env = builderContext.HostingEnvironment; config.AddJs ... -
经过2天的测试和尝试,我找到了工作解决方案。 主要问题是,在ASP.NET Core MVC 2.0中,身份验证方法被注册为服务而不是中间件。 这意味着它们必须在ConfigureServices方法而不是Configure ,因此无法在注册时进行分支以创建分支。 此外,auth系统使用AuthenticationOptions来确定将使用哪种身份验证方法。 从我发现的测试中, AuthenticationOptions实例在请求之间共享,因此无法修改它以调整DefaultScheme 。 经过一番挖掘,我 ...
-
在ASP.NET Core MVC中,MVC和Web API之间没有区别(就像MVC 5 / Web API 2中那样)。 无论请求是否返回View或其他类型的ActionResult,路由都应该以相同的方式工作。 也就是说,属性路由是ASP.NET Core MVC中的默认约定,因为它使路由逻辑更接近将响应路由的代码。 您仍然可以在Startup.Configure中设置全局路由(如您所见),但传统的推荐方法是在控制器和/或操作级别使用属性。 如果你看到特定(web api)动作没有使用你全局设置的路线的 ...
-
如果你使用的是project.json,确保你有这样的东西: "publishOptions": { "include": [ "wwwroot", "web.config", "Views", "myconfig.json" ] }, 这指定发布中应包含哪些文件夹和文件。 在新的.csproj格式你应该有这样的东西:
如何检查MVC Core配置文件中的某个部分是否存在?(How to check if a section in MVC Core configuration file exist?)[2022-02-07]
使用GetChildren方法: var keysExists = Configuration.GetChildren().Any(x => x.Key == "Keys")); Use GetChildren method: var keysExists = Configuration.GetChildren().Any(x => x.Key == "Keys"));带有Identity Server 4的MVC Core和MVC Core API(MVC Core and MVC Core API with Identity Server 4)[2022-04-19]
这完全取决于你。 您可以让MVC项目成为API项目的客户端,也可以让两个项目都使用相同的底层数据层。 就个人而言,我倾向于选择后者。 实质上,您只需创建一个实现服务层的.NET Standard 2.0类库。 此类库将与您的数据库( DbContext )进行交互,并为您的MVC / API需要进行的调用抽象逻辑。 然后,两个项目都可以简单地引用这个类库,并使用您的服务层来完成他们需要做的事情。 如果您想将MVC项目用作客户端,那么,是的,您只需使用HttpClient向您的API发出请求即可。 RestS ...MVC 6配置验证(MVC 6 Configuration Validation)[2021-10-01]
我去了[Required]并在ServiceSettings强制任何属性,并在Startup.ConfigureServices添加了以下内容: services.Configure(settings => { ConfigurationBinder.Bind(Configuration.GetSection("ServiceSettings"), settings); EnforceRequiredStrings(settings); }) 以下是St ... 请参阅https://github.com/aspnet/Mvc/issues/4785 AspNetCore.Mvc已经为您设置了所有基本内容 如果你想使用AspNetCore.Mvc.Core你必须自己配置它们 使用AspNetCore.Mvc似乎是明智的,除非你知道你需要AspNetCore.Mvc.Core 如果您使用.AddMvc()那么您将获得许多“自以为是”的功能,例如您正在构建什么类型的应用程序,哪些格式化程序已注册,以及以何种顺序,默认情况下存在哪些应用程序约定。 如果您使用.AddMvc ...为什么不跟随作者并使用额外的验证编写自己的扩展方法? 看看这里。 这是services.Configure<>的源代码services.Configure<>方法: namespace Microsoft.Extensions.DependencyInjection { ////// Extension methods for adding options services to the DI container. /// public stati ...我认为最合适的方法是提供自定义ConfigurationExtension 。 例如 var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .AddDatabaseValues(); 您必须 ...相关文章
更多- IOS7 position:fixed 定位问题
- div中table100%宽度的浏览器兼容性问题
- Lua table(表、数组、字典)
- Guava集合工具类-Table接口映射处理
- SWT中关于监听问题!!!
- table-Oceanus配置说明
- 求教一个 table的css
- swt网格式布局和表格式布局
- Lua 元表(Metatable)改变table的行为
- Guava学习笔记:Guava新集合-Table等
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)