在相同的JMenu内对JMenuItem组进行排序,而不对其他JMenuItem进行排序。

huangapple go评论65阅读模式
英文:

Sorting groups of JMenuItems inside the same JMenu without sorting other JMenuItems

问题

我现在将翻译你的请求,只返回翻译好的部分,不包含其他内容:

  1. Establish new Connection(建立新连接)
  2. A JSeparator
  3. 3 Standard revisor connection entries that always stay the same(3个始终保持不变的标准修订连接条目)
  4. JSeparator
  5. Multiple entries for the defined Connection-Groups为定义的连接组添加多个条目
  6. JSeparator
  7. Multiple entries not belonging to a group不属于任何组的多个条目
  8. JSeparator
  9. Close Connection(关闭连接)

排序算法需要按字母顺序对第5和第7部分中的条目进行排序,而不对其他菜单项进行排序。

英文:

An application I'm working on let's users establish connections to some industry-specific Hardware. Those connections (IP/Host couplings) can be saved and given a name, and optionally a group attribute that will pair saved connections belonging to the same group.

I now have a JMenu that provides the user with all kinds of options to do with connections. The structure of the JMenu is as follows:

  1. Establish new Connection
  2. A JSeparator
  3. 3 Standard revisor connection entries that always stay the same
  4. JSeparator
  5. Multiple entries for the defined Connection-Groups
  6. JSeparator
  7. Multiple entries not belonging to a group
  8. JSeparator
  9. Close Connection

The sorting algorithm I need would have to sort the groupped entries from 5. alphabetically and the ungroupped entries from 7. alphabetically, without sorting any other MenuItems. Basically, how do I sort sub-groups of MenuItems inside a JMenu without sorting all of them?

答案1

得分: 1

这段代码的翻译如下:

"It's been a while since I've used Swing, but I'm assuming you can store the string for each menu item's text in an array of Objects and render the menu items in a for loop. You could then store 1, 3, and 9 as strings in the array, and 5 and 7 as ArrayLists of strings within the first array. You could then insert a JSeparator between each item in the first array when you render it, making sure that each item is a string by using the instanceof keyword. If the item is not an instanceof string and it is an instanceof ArrayList<String>, you could render a menu item for each string in that inner ArrayList. You can sort the items in each inner ArrayList alphabetically using Collections.sort(mainArray[indexesOfSubarrays])."

英文:

It's been a while since I've used Swing, but I'm assuming you can store the string for each menu item's text in an array of Objects and render the menu items in a for loop. You could then store 1, 3, and 9 as strings in the array, and 5 and 7 as ArrayLists of strings within the first array. You could then insert a JSeparator between each item in the first array when you render it, making sure that each item is a string by using the instanceof keyword. If the item is not an instanceof string and it is an instanceof ArrayList&lt;String>, you could render a menu item for each string in that inner ArrayList. You can sort the items in each inner ArrayList alphabetically using Collections.sort(mainArray[indexesOfSubarrays]).

huangapple
  • 本文由 发表于 2020年8月10日 16:05:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/63336348.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定