我使用BorderLayout
,我在北边放了一些东西,在南边放了一些东西,但是这两个面板(北和南)之间总是有一条白线,如何删除这条线?
我尝试为BorderLayout
设置setVGap
和HGap
,并且我尝试设置父框架的背景颜色,但没有也不起作用
感谢您的帮助,现在我在这里放了一些代码,也许您可以看到一些错误。
公共(public)类 MediaSelector 扩展 JPanel{
public MediaSelector() {
setBorder(new EmptyBorder(-1, -1, 0, -2));
setBackground(Color.red);
setLayout(new BorderLayout());
JPanel panel1 = new JPanel();
panel1.setBackground(new Color(home_screen_r,home_screen_g,home_screen_b));
panel1.setLayout(null);
JPanel buttonPane = new JPanel();
GridBagLayout gridbag = new GridBagLayout();
buttonPane.setLayout(gridbag);
buttonPane.setBackground(new Color(footer_r, footer_g, footer_b));
add("North", panel1);
add("South", buttonPane);
}
main(){
mediaSelectorPane = new MediaSelector();
mediaSelectorPane.setOpaque(true); // content panes must be opaque
frame.setContentPane(mediaSelectorPane);
if (isFullScreen) {
frame.dispose();
frame.setUndecorated(true);
frame.getGraphicsConfiguration().getDevice()
.setFullScreenWindow(frame);
frame.setVisible(true);
}
}
最佳答案
实际上,对我来说效果很好。一定是你在做其他事情。
public class TestLayout19 {
public static void main(String[] args) {
new TestLayout19();
}
public TestLayout19() {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
}
JPanel north = new TestPane(Color.RED);
JPanel center = new TestPane(Color.GREEN);
JPanel south = new TestPane(Color.BLUE);
JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(north, BorderLayout.NORTH);
// frame.add(center, BorderLayout.CENTER);
frame.add(south, BorderLayout.SOUTH);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
public class TestPane extends JPanel {
public TestPane(Color bg) {
setBackground(bg);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(100, 100);
}
}
}
在您提问之前,您需要先分享一个代码示例,然后我们才能进一步帮助您
关于java - 如何删除java borderlayout中南北面板之间的间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15264267/