我是 Java 新手,我想做的是用一堆影像生成一個 GUI 我已經設法生成了一堆影像,但是,它們在水平方向之間有不必要的空間,有什么辦法可以擺脫目前我正在像這樣生成它們?
setLayout(new FlowLayout());
int numberOfTabs = 4;// number of times image is shown
for(int i = 0; i<numberOfTabs;i ) {
add(
new JLabel(new ImageIcon(getClass().getClassLoader().getResource("Path to image"))));
//creates a new image anonymous object and adds it to the jframe
}
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Sheetssss");
pack();
setVisible(true);
//also in this context this = a Jframe object so all these methods can be called without an object reference
是否有其他方法可以呼叫,以便可以將水平間距設定為 0?如下圖所示,圖片之間有空間,圖片之間的兩條垂直黑線應該是重疊的
謝謝
uj5u.com熱心網友回復:
你只需要改變
setLayout(new FlowLayout())
到
setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/434907.html
上一篇:在Java中對齊圖形時遇到問題
