且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用户加载新图像时,是否可以更新显示窗口?

更新时间:2023-12-05 16:32:58

您正在使用我们无法访问的第三方/自定义组件,因此无法提供任何真实"的解决方案. ..

You're using 3rd party/custom components, to which we don't have access to, so it's impossible to provide any "real" solutions, however...

但是,当按下loadImage按钮时,图像永远不会更新

However the image never gets updated when the loadImage button is pressed

这可能有多种原因,假设图像已正确加载,则可能是:

This could be for any number of reasons, assuming that the image was loaded correctly, its possible that:

  • 尚未将图像添加到任何可以在屏幕上渲染的图像和/或尚未将渲染添加到附着在屏幕上的任何图像
  • 通常,您可以在要更新的组件上调用repaint,它应该"触发一个新的绘制过程(不是图像,而是用来渲染它的东西)
  • 您可能需要在用于显示图像的组件上调用revalidate,以触发新的布局遍历,如果正确构建了UI,则会更新组件层次结构.
  • The image hasn't been added to anything which can render it on the screen and/or the render hasn't been added to anything attached to the screen
  • Generally, you can call repaint on the component you want updated, which "should" trigger a new paint pass (not the image, but what ever is been used to render it)
  • You may need to call revalidate on the component used to display the image to trigger a new layout pass, which, if you've built your UI correctly, will update the component hierarchy.

我的JScrollbar也没有出现在我想要的框架中.它没有滚动槽,并且与我的图像窗口没有相同的宽度.如何更改JScrollbar的参数以反映这一点?

Also my JScrollbar does not appear in the frame as I want it. It does not scroll trough and does not have the same width as my image window. How do I change the parameters of my JScrollbar to reflect that?

这是一个更为复杂的问题.首先,您应该在建立UI后在框架上调用setVisible,否则它可能无法布局/绘制内容(除非您手动调用revalidate/repaint).

That's a much more complicated issue. First, you should call setVisible on your frame AFTER you've established the UI, otherwise it may not layout/paint the contents (unless you call revalidate/repaint manually).

您不需要使用JScrollBar,而是应该使用JScrollPane.

You shouldn't need to use JScrollBar, but instead, should be using JScrollPane.

强烈建议您先通读以下内容:

I would, strongly, recommend you start by reading through:

  • Creating a GUI With JFC/Swing
  • How to Use Scroll Panes
  • Laying Out Components Within a Container

以更好地基本了解UI的API和组件

to get a better basic understand of the UI its API and components