简体   繁体   English

在其他组件之间的Java Swing中插入组件的最快方法是什么?

[英]Which is the fastest way to insert component in Java Swing between other components?

I'm making a kind of editor which have a blocks (JPanel's) instead of words (with text-like flow and cursor - blinking JPanel). 我正在制作一种具有块(JPanel的)而不是单词的编辑器(具有类似文本的流和光标-闪烁的JPanel)。

I need a fast way to add a Swing component (new block) between existing components in situations like: 我需要一种在以下情况下在现有组件之间添加Swing组件(新块)的快速方法:

  • mouse click between JPanels to place cursor there 在JPanel之间单击鼠标以将光标放在此处
  • add new block element between existing elements. 在现有元素之间添加新的块元素。

The problem is, that rebuilding document (.removeAll() and .add() all blocks) take 3-4 seconds with document containing 300-400 blocks. 问题在于,对于包含300-400个块的文档,重建文档(.removeAll()和.add()所有块)需要3-4秒。

I can easily speed up cursor positioning, by inserting empty blocks between each block and place cursor there, but what if I need a new clean block between existing blocks ? 通过在每个块之间插入空块并将光标放在那里,我可以轻松地加快光标定位,但是如果我需要在现有块之间放置一个新的干净块,该怎么办?

I know that some way is to create my own "rendering engine" but can I achieve this a lot easier with swing components ? 我知道某种方法可以创建自己的“渲染引擎”,但是我可以通过swing组件轻松实现这一点吗?

I would say you should add just one block with proper constraint. 我想说,您应该只添加一个具有适当约束的块。 Then it's task of LayoutManager to place the block correctly between another and layout all the children components. 然后,LayoutManager的任务是将块正确地放置在另一个块之间,并对所有子组件进行布局。

您需要编写自己的LayoutManager。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM