문제

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:

alt text http://dl.dropbox.com/u/2652228/Screen%20shot%202010-03-25%20at%208.10.07%20PM.png

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?

도움이 되었습니까?

해결책

Add an EmptyBorder to the panel. You can specify the left inset to be whatever you want.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top