Buongiorno a tutti.
Nell'implementare un'applicazione in Java mi sono imbattuto in un problema che a priori mi sembrava facilmente risolvibile ma che in realtà così non è stato.
Il problema è semplice: non riesco ad impostare un JScrollPane per un frame in modo che anche quando riduco le dimensioni del frame oppure per dimensioni ridotte del monitor sul quale visualizzo l'applicazione mi permetta di riuscire comunque a visualizzare il contenuto di tutto ciò che è stato inserito nell'applicazione.
Riporto le parti di codice più importanti in questo senso:
codice:
public class Quest extends JPanel implements Printable, ActionListener
{
public Quest (JFrame f) throws ParseException {
JPanel Inclusion = new JPanel(new FlowLayout());
Inclusion.add(inclusion);
JPanel nulla = new JPanel(new FlowLayout());
JPanel labels = new JPanel(new GridLayout(1,0));
labels.add(label1);
labels.add(codicepaziente);
JPanel labels1 = new JPanel(new GridLayout(1,0));
labels1.add(label3);
labels1.add(dataField);
JPanel labels2 = new JPanel(new GridLayout(1,0));
labels2.add(label4);
labels2.add(eta);
JPanel labels3 = new JPanel(new GridLayout(1,0));
labels3.add(label2);
labels3.add(sì_CMT1A);
labels3.add(no_CMT1A);
JPanel outcome1 = new JPanel(new GridLayout(1,0));
outcome1.add(label11);
outcome1.add(sì_outcome);
outcome1.add(no_outcome);
JPanel walk1 = new JPanel(new GridLayout(1,0));
walk1.add(label12);
walk1.add(sì_walk);
walk1.add(no_walk);
JPanel labels4 = new JPanel(new GridLayout(1,0));
labels4.add(label6);
labels4.add(Mobility_scale);
JPanel labels5 = new JPanel(new GridLayout(1,0));
labels5.add(label7);
labels5.add(Tinetti_Scale);
JPanel consenso = new JPanel(new GridLayout(1,0));
consenso.add(label8);
consenso.add(sì_Consenso);
consenso.add(no_Consenso);
JPanel nulla1 = new JPanel(new FlowLayout());
JPanel nulla2 = new JPanel(new FlowLayout());
JPanel nulla3 = new JPanel(new FlowLayout());
JPanel nulla4 = new JPanel(new FlowLayout());
JPanel nulla5 = new JPanel(new FlowLayout());
JPanel nulla6 = new JPanel(new FlowLayout());
JPanel Exclusion = new JPanel(new FlowLayout());
Exclusion.add(exclusion);
JPanel CMT = new JPanel(new GridLayout(1,0));
CMT.add(cmt);
CMT.add(sì_cmt);
CMT.add(no_cmt);
JPanel AFFEZIONI = new JPanel(new GridLayout(1,0));
AFFEZIONI.add(affezioni);
AFFEZIONI.add(sì_affezioni);
AFFEZIONI.add(no_affezioni);
JPanel CAUSE = new JPanel(new GridLayout(1,0));
CAUSE.add(cause_associate);
CAUSE.add(sì_cause);
CAUSE.add(no_cause);
JPanel NONAMBULANTI = new JPanel(new GridLayout(1,0));
NONAMBULANTI.add(pazienti_nonambulanti);
NONAMBULANTI.add(sì_nonambulanti);
NONAMBULANTI.add(no_nonambulanti);
Datanascita= dataField.getText();
Box group = Box.createVerticalBox();
group.add(Inclusion);
group.add(nulla);
group.add(labels);
group.add(labels1);
group.add(labels2);
group.add(labels3);
group.add(nulla1);
group.add(outcome1);
group.add(nulla1);
group.add(walk1);
group.add(nulla1);
group.add(labels4);
group.add(labels5);
group.add(consenso);
group.add(nulla1);
group.add(nulla2);
group.add(Exclusion);
group.add(nulla3);
group.add(CMT);
group.add(nulla4);
group.add(AFFEZIONI);
group.add(nulla5);
group.add(CAUSE);
group.add(nulla6);
group.add(NONAMBULANTI);
JPanel container = new JPanel(new FlowLayout(FlowLayout.RIGHT));
container.add(group);
rightTextArea.setRows(1);
rightTextArea.setColumns(1);
rightTextArea.setEditable(false);
JLabel Randomization = new JLabel("Treatment arm");
Randomization.setFont(myFont);
JPanel Fondo = new JPanel(new GridLayout(1,0));
Fondo.add(Randomization);
A.setText("A");
B.setText("B");
ButtonGroup Trattamento = new ButtonGroup();
Trattamento.add(A);
Trattamento.add(B);
Fondo.add(A);
Fondo.add(B);
JLabel Randomization_date = new JLabel("Data randomizzazione ");
Randomization_date.setFont(myFont);
Randomization_date.setLabelFor(Data_attuale);
JPanel Randomization1 = new JPanel(new GridLayout(1,0));
Randomization1.add(Randomization_date);
Randomization1.add(Data_attuale);
JPanel Fondo1 = new JPanel(new FlowLayout(FlowLayout.CENTER,70,15));
Fondo1.add(Fondo,FlowLayout.LEFT);
Fondo1.add(Randomization1, FlowLayout.CENTER);
Fondo1.add(Stampa,FlowLayout.RIGHT);
JPanel layout = new JPanel(new BorderLayout());
layout.add(container,BorderLayout.CENTER);
layout.add(Fondo1,BorderLayout.SOUTH);
layout.add(rightTextArea,BorderLayout.NORTH);
add(layout);
}
private static void createAndShowGUI() throws ParseException {
JFrame frame = new JFrame("Randomizzazione");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final Quest newContentPane = new Quest(frame);
newContentPane.setOpaque(false);
frame.setContentPane(newContentPane);
frame.addWindowListener(new WindowAdapter() {
public void windowActivated(WindowEvent e) {
newContentPane.resetFocus();
}
});
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.put("swing.boldMetal", Boolean.TRUE);
createAndShowGUI();
} catch (ParseException ex) {
Logger.getLogger(Quest.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
};
}
Le parti relative ad ActionListener le ho rimosse.
Ho già provato sia ad inserire un JScrollPane sia nel frame sia inserendo "layout" in un ulteriore pannello però le barre funzionano solo internamente e se riduco la finestra esterna del frame in realtà vedo solo parte degli oggetti e non vedo più nemmeno le barre interne.
Temo possa essere un problema di qualche layout.
Grazie a chiunque mi voglia aiutare.