我正在创建一个jcomponents容器,它看起来像一个钢琴键盘。黑色键看起来像这样(groovy)
def setBlackNotes(buttons) {
def octaves = (int)(buttons.size() / 5)
def gridLayout = new GridLayout(1, octaves*7);
def blackNotePanel = new JPanel(gridLayout)
this.add blackNotePanel
def i = 0
octaves.times {
2.times {
blackNotePanel.add buttons[i++]
}
blackNotePanel.add Box.createHorizontalBox()
3.times {
blackNotePanel.add buttons[i++]
}
blackNotePanel.add Box.createHorizontalBox()
}
}
这正是我需要的,看起来像这样:
alt text http://dl.dropbox.com/u/2652228/Screen%20shot%202010-03-25%20at%208.10.07%20PM.png
但我想把这个移到右边半个键宽。
我所有的尝试
blackNotePanel
超过任意宽度
--将它包装为borderlayout、miglayout等——失败或从根本上改变了gridlayout的间距。
有什么建议可以把这个移到右边任意像素的位置吗?