英文:
Sorting groups of JMenuItems inside the same JMenu without sorting other JMenuItems
问题
我现在将翻译你的请求,只返回翻译好的部分,不包含其他内容:
- Establish new Connection(建立新连接)
- A JSeparator
- 3 Standard revisor connection entries that always stay the same(3个始终保持不变的标准修订连接条目)
- JSeparator
- Multiple entries for the defined Connection-Groups(为定义的连接组添加多个条目)
- JSeparator
- Multiple entries not belonging to a group(不属于任何组的多个条目)
- JSeparator
- 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:
- Establish new Connection
- A JSeparator
- 3 Standard revisor connection entries that always stay the same
- JSeparator
- Multiple entries for the defined Connection-Groups
- JSeparator
- Multiple entries not belonging to a group
- JSeparator
- 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<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])
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论