Tu pourrais je pense assez simplement...
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Tu pourrais je pense assez simplement générer un fichier HTML pour avoir la présentation de tes données comme tu le veux (éventuellement avec un peu de CSS)
Une fois ce fichier fait il te reste à l'imprimer et pour ça tu as print(File)
Pour t'en sortir, le mieux est d'essayer de placer ce que tu veux imprimer dans un même JPanel et ensuite, d'imprimer ce JPanel.
import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JTextArea; import fr.julien.dashboard.vue.DashBoard; import fr.julien.dashboard.vue.PanelTitre; public class Lanceur { public static void main(String[] args) { final List<JComponent> panels = new ArrayList<JComponent>(); for(int i=0; i<8; i++) { panels.add(new PanelTitre("Panel "+i, creerTextArea(i))); } final JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLayout(new GridLayout(1,0)); f.setLayout(new BorderLayout()); f.add(new DashBoard(panels)); f.setSize(650, 450); f.setVisible(true); JButton b = new JButton("add panel"); f.add(b, BorderLayout.SOUTH); b.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub panels.add(new PanelTitre("Panel ", creerTextArea(10))); f.getContentPane().repaint(); } }); } private static JTextArea creerTextArea(int i){ JTextArea texte = new JTextArea("Texte du Panel numéro "+i+"."); texte.setEditable(false); texte.setOpaque(false); return texte; } }
f.setLayout(new GridLayout(1,0));//Supprime cette ligne f.setLayout(new BorderLayout()); //.... f.add(new DashBoard(panels, BorderLayout.CENTER));//Ajoute BorderLayout.CENTER
public void mouseDragged(MouseEvent e) { panelTitre.setLocation( (int)(e.getX()-dashboard.getDragLocation().getX()+panelTitre.getX()), (int)(e.getY()-dashboard.getDragLocation().getY()+panelTitre.getY()) ); panelTitre.setSize( (int)(e.getX()-dashboard.getDragLocation().getX()+panelTitre.getX()), (int)(e.getY()-dashboard.getDragLocation().getY()+panelTitre.getY()) ); dashboard.repaint(); }
int marge=5; if(e.getX()<marge || e.getX()>composant.getWidth()-marge || e.getY()<marge || e.getY()>composant.getHeight()-marge){ //Instructions effectuée dans le cas ou tu es sur le border } else { //Si tu es sur l'interieur }
public void mouseDragged(MouseEvent e) { int marge=5; if(e.getX()<marge || e.getX()>panelTitre.getWidth()-marge || e.getY()<marge || e.getY()>panelTitre.getHeight()-marge){ panelTitre.setSize( (int)(e.getX()-dashboard.getDragLocation().getX()+panelTitre.getX()), (int)(e.getY()-dashboard.getDragLocation().getY()+panelTitre.getY()) ); } else { panelTitre.setLocation( (int)(e.getX()-dashboard.getDragLocation().getX()+panelTitre.getX()), (int)(e.getY()-dashboard.getDragLocation().getY()+panelTitre.getY()) ); } dashboard.repaint(); }
Par contre, tu n'as pas de méthode setresizable(true) pour les JPanel.