Swing:什么是实现完全可扩展的组件的好方法? [英] Swing: What is a good way to implement fully-scalable components?

查看:100
本文介绍了Swing:什么是实现完全可扩展的组件的好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个具有可滚动和可缩放(可缩放)视图的应用程序.在此视图内,我想放置其他组件(其中大多数是自定义的JPanel s和JInternalFrame s).

I am creating an application which has a scrollable and scalable (zoomable) view. Inside this view I want to place other components (most of them customized JPanels and JInternalFrames).

诸如字体和边框之类的东西以及诸如按钮之类的子元素需要可扩展.应该只有容器组件的尺寸和位置.

Things such as fonts and borders, and sub-elements such as buttons don't need to be scalable. Only dimensions and position of container components should be.

您认为,什么是实现可伸缩组件的好方法?

编辑:我说的是调整整个布局的大小,包括所有 成分.请考虑诸如具有缩放功能的可视UML编辑器之类的东西.

I'm talking about resizing the entire layout including all components. Please think of something such as a visual UML editor with zoom functionality.

我的替代方法是:

  • 创建自定义布局管理器;
  • 创建自定义可调整大小的子组件;
  • 创建一个自定义容器,该容器将负责调整其子组件的大小;
  • 还有其他事情吗?

可能的问题:

  • 样板代码;
  • 需要提供对组件的其他自定义属性的访问;
  • 代码中组件的表示不直接(不一致).
  • 还有别的吗?

推荐答案

我已经通过创建自定义布局管理器来做到这一点.框架上的每个组件(或更确切地说是组件类)都有一个标记,该标记用于在调整容器大小时是否应调整大小(例如,调整表的大小,不调整按钮的大小).那些未调整大小的容器将在调整容器大小时移动.

I've done that by creating a custom layout manager. Every component (or rather component class) on the frame has a marker whether or not it shall be resized when the container is resized (e.g. tables are resized, buttons are not). Those which are not resized are moved when the container is resized.

这用于制作可调整大小的表单,而无需任何手动设置,即仅通过为每个组件指定x/y/length/width来定义表单(无需进一步的对齐信息).

This is used to make resizeable forms without any manual setup, i.e. forms are defined by just specifying x/y/length/width for each component (no further alignment info).

这篇关于Swing:什么是实现完全可扩展的组件的好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆