Piano Keys using GridLayout (or Something Else)
Posted
by yar
on Stack Overflow
See other posts from Stack Overflow
or by yar
Published on 2010-03-25T19:04:14Z
Indexed on
2010/03/25
19:13 UTC
Read the original article
Hit count: 446
I am creating a container of JComponents which will look like a piano keyboard. The black keys look like this (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()
}
}
Which is just what I need, and looks like this:
but then I'd like to move this over to the right by half-a-key width. All of my attempts to move the blackNotePanel
over by an arbitrary width -- wrapping it a BorderLayout, a MigLayout, etc. -- have failed or changed the spacing of the GridLayout radically.
Any suggestions on how to move this over to the right by an arbitrary amount in pixels?
© Stack Overflow or respective owner