How to display clickable images on a panel?

已回答

Hi! I do generative art using Kotlin and OPENRNDR. In a project I have tens, maybe hundreds of small Kotlin programs that produce different images each. I'm trying to create a simple thumbnails plugin that would help me find the program I'm looking for. Reading the names and running programs is a very slow process. The plugin would do the following:

  • scan all the kotlin files in my project.
  • extract a comment at the top of each file pointing to an image file (a png or svg thumbnail).
  • display a panel with a grid of clickable images, ideally with name and date.
  • when I click an image, the corresponting kotlin file is opened.

I'm currently able to display a panel, which was already hard because this doesn't tell you what to do with it, I figured out after hours of searching. This helped.

The UI DSL doesn't seem to include an image component. The page about icons and images mentions images only in the title, but doesn't show how to programatically load and display images either. I tried with

row { JLabel(ImageIcon(img)) }

but it doesn't show up.

The only thing I've found is this 11 year old example. Is there anything better than that?

Thanks!

0

The UI DSL is meant for simple, row/cell-based UIs like forms. You're free to use "plain" Swing if it suits you better.

Please see com.intellij.openapi.util.IconLoader, com.intellij.util.IconUtil for possible candidates or provide actual sources of your plugin to understand where `img` comes from.

 

0

请先登录再写评论。