У меня есть панель кода нижеНевозможно установить BoxLayout (JPanel) правильно GridLayout/FlowLayout
public class PhotoBox extends JPanel {
private JLabel photoIcon;
private JLabel photoName;
private JLabel print;
private ImageHelper imageHelper;
public PhotoBox(File file, JLabel print) throws IOException {
imageHelper = new ImageHelper();
this.photoIcon = new JLabel();
this.photoIcon.setIcon(imageHelper.createThumbnails(file));
this.photoIcon.setMaximumSize(new Dimension(200, 150));
this.photoIcon.setAlignmentX(Component.CENTER_ALIGNMENT);
this.photoName = new JLabel();
photoName.setText((file.getName().length()) > 20 ? file.getName().substring(0,10)+".." : file.getName());
this.photoName.setAlignmentX(Component.CENTER_ALIGNMENT);
this.print = new JLabel();
this.print.setText(print.getText());
this.print.setAlignmentX(Component.CENTER_ALIGNMENT);
setLayout(new BoxLayout(this , BoxLayout.Y_AXIS));
setBorder(BorderFactory.createLineBorder(Color.black));
//setPreferredSize(new Dimension(200,150));
add(this.photoIcon);
add(this.photoName);
add(this.print);
}
}
Теперь я добавляю список такой панели на другой JPanel с имеет GridLayout
JPanel tile = new JPanel();
GridLayout layout = new GridLayout(0,4);
tile.setLayout(layout);
PhotoBox vBox = new PhotoBox(file,filePrints.get(file.getName()));
tile.add(vBox);
Но то, что я, наконец, получить что-то вроде этого
Я не понимаю, почему это все пространство занимает все мои объекты PhotoBox. Я хочу, чтобы изображения были близки друг к другу. Не забыть, я уже пробовал PrefSize(), и он не работает.
Использование WrapLayout/FlowLayout
Edit:
Что теперь я чувствую, что проблема с BoxLayout
в PhotoBox
.
Спасибо, что именно там, где проблема была – ItachiUchiha
Нет проблем .. :) – TheLittleNaruto