Reputation: 619
I was building a view and then I realized that I needed to put too much information inside, so it would not fit in the window. So I decided to create a JScrollPane to put all the elements inside, and continue including new elements if needed, be able to see it all in my window.
This is the code for my scroll pane:
public JPanel getActionsPane() {
if (Objects.isNull(actionsPane)){
actionsPane = new JPanel();
actionsPane.setLayout(null);
actionsPane.setBounds(0, 29, 1580, 1450);
addComponents();
}
return actionsPane;
}
public JScrollPane getActionsScrollPane() {
if (Objects.isNull(actionsScrollPane)){
actionsScrollPane = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
actionsScrollPane.add(getActionsPane());
actionsScrollPane.setLayout(new ScrollPaneLayout());
actionsScrollPane.setBounds(0, 29, 593, 400);
actionsScrollPane.setViewportView(getActionsPane());
}
return actionsScrollPane;
}
But when I compile, I can only see this:
[
As you can see, the scroll is not being showed. I have not worked very much with JScrollPane in the past, maybe I am missing some propierty to enable the scrolls?
Upvotes: 2
Views: 326
Reputation: 619
I follow several advices, tried to use layouts, none of this worked for me. Finally, thanks to a friends suggestion, I manage to do it, without layouts, just modifying my old approach.
public UI_ReembolsoFondoRegistrar(Window window) {
super(window);
setBounds(100, 100, 593, 750);
setLocationRelativeTo(null);
setTitle("Reembolsar el fondo para dietas y pagos menores");
buttonPane.add(getBtnAceptar());
buttonPane.add(getBtnCancelar());
contentPanel.setLayout(null);
contentPanel.add(getLblFecha());
contentPanel.add(getActionsScrollPane());
contentPanel.add(getLblCustodio());
contentPanel.add(getCbxCustodio());
contentPanel.add(getLblContab());
contentPanel.add(getCbxContab());
contentPanel.add(getLblRevisado());
contentPanel.add(getCbxRevisado());
contentPanel.add(getLblAprobado());
contentPanel.add(getCbxAprobado());
contentPanel.add(getLblCheque());
contentPanel.add(getTxtCheque());
contentPanel.add(getLblFecha_1());
contentPanel.add(getDateChooser());
contentPanel.add(getLblAnotado());
contentPanel.add(getCbxAnotado());
contentPanel.add(getSeparator_2());
}
public JPanel getActionsPane() {
if (Objects.isNull(actionsPane)){
actionsPane = new JPanel();
actionsPane.setLayout(null);
actionsPane.setPreferredSize(new Dimension(1580,525));
addComponents();
}
return actionsPane;
}
public JScrollPane getActionsScrollPane() {
if (Objects.isNull(actionsScrollPane)){
actionsScrollPane = new JScrollPane(getActionsPane(), JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
actionsScrollPane.setViewportView(getActionsPane());
actionsScrollPane.setBounds(0,28,593,480);
}
return actionsScrollPane;
}
private void addComponents(){
actionsPane.add(getPanelGastosViaje());
actionsPane.add(getPanelValePM());
actionsPane.add(getLblCuenta());
actionsPane.add(getCbxCuenta());
actionsPane.add(getLblOCC());
actionsPane.add(getCbxOCC());
actionsPane.add(getLblCUP());
actionsPane.add(getTxtCUP());
actionsPane.add(getTxtTotalCUP());
actionsPane.add(getBtnDesCUP());
actionsPane.add(getSeparator_1());
actionsPane.add(getLblCUC());
actionsPane.add(getTxtCUC());
actionsPane.add(getTxtTotalCUC());
actionsPane.add(getBtnDesCUC());
actionsPane.add(getContrapartidasTableJP());
}
Upvotes: 5