سؤال

I know that when I create an instance of tabbed panes I set the position as such:

 jtp = new JTabbedPane(SwingConstants.LEFT)

My question is that is it possible to set the position to the left as above, but to shift the starting position a little bit downwards? I do not want the first tab appearing at the very top of the left hand side. I want to leave some empty space. Is that possible? Thanks.

هل كانت مفيدة؟

المحلول 2

I managed to find a work around for this problem. I did this by creating a "dummy" icon which was basically a square with the same colour as the background colour of the tabbed panes. I then set this icon as the icon for a "dummy" tabbed pane and disabled the tab:

jtp.addTab("", dummyIcon, null);
jtp.setEnabledAt(0, false);

By resizing the icon I could make the first tabbed pane take up as much space as i wanted since the panes don't have to be the same size. This way The first tab was not clickable and it had a colour similar to the background colour of the panel, so it appeared as if the space was empty.

نصائح أخرى

You can pack your component into javax.swing.Box add shift it:

jtp.add("Component shifted vertically", shiftVertical(your_component, 5)); // 5 px or more

public static Box shiftVertical(JComponent component, int size){
    Box vBox = Box.createVerticalBox();
    vBox.add(Box.createVerticalStrut(size)); 
    vBox.add(component);

    return vBox;
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top