SHOW:
|
|
- or go back to the newest paste.
1 | import java.awt.BorderLayout; | |
2 | import java.util.Arrays; | |
3 | import java.util.LinkedList; | |
4 | import java.util.List; | |
5 | ||
6 | import javax.swing.JButton; | |
7 | import javax.swing.JFrame; | |
8 | import javax.swing.JLabel; | |
9 | import javax.swing.JPanel; | |
10 | import javax.swing.JScrollPane; | |
11 | import javax.swing.JTabbedPane; | |
12 | import javax.swing.JTable; | |
13 | import javax.swing.SwingUtilities; | |
14 | import javax.swing.table.DefaultTableModel; | |
15 | ||
16 | public class MyFrame extends JFrame { | |
17 | - | public class MyFrame extends JFrame{ |
17 | + | |
18 | - | |
18 | + | |
19 | private JTabbedPane tabs; | |
20 | private JButton runButton; | |
21 | ||
22 | - | |
22 | + | public MyFrame() { |
23 | - | public MyFrame(){ |
23 | + | |
24 | panel1 = new JPanel(); | |
25 | runButton = new JButton("go!"); | |
26 | runButton.addActionListener(new java.awt.event.ActionListener() { | |
27 | public void actionPerformed(java.awt.event.ActionEvent evt) { | |
28 | - | public void actionPerformed(java.awt.event.ActionEvent evt) { |
28 | + | runButtonActionPerformed(evt); |
29 | - | runButtonActionPerformed(evt); |
29 | + | |
30 | - | } |
30 | + | }); |
31 | - | }); |
31 | + | |
32 | tabs.addTab("first tab", panel1); | |
33 | this.add(tabs); | |
34 | pack(); | |
35 | } | |
36 | ||
37 | - | |
37 | + | |
38 | try { | |
39 | - | try { |
39 | + | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager |
40 | - | for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { |
40 | + | .getInstalledLookAndFeels()) { |
41 | - | if ("Nimbus".equals(info.getName())) { |
41 | + | if ("Nimbus".equals(info.getName())) { |
42 | - | javax.swing.UIManager.setLookAndFeel(info.getClassName()); |
42 | + | javax.swing.UIManager.setLookAndFeel(info.getClassName()); |
43 | - | break; |
43 | + | break; |
44 | - | } |
44 | + | } |
45 | - | } |
45 | + | |
46 | - | } catch (ClassNotFoundException ex) { |
46 | + | } catch (ClassNotFoundException ex) { |
47 | - | java.util.logging.Logger.getLogger(MyFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
47 | + | java.util.logging.Logger.getLogger(MyFrame.class.getName()).log( |
48 | - | } catch (InstantiationException ex) { |
48 | + | java.util.logging.Level.SEVERE, null, ex); |
49 | - | java.util.logging.Logger.getLogger(MyFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
49 | + | } catch (InstantiationException ex) { |
50 | - | } catch (IllegalAccessException ex) { |
50 | + | java.util.logging.Logger.getLogger(MyFrame.class.getName()).log( |
51 | - | java.util.logging.Logger.getLogger(MyFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
51 | + | java.util.logging.Level.SEVERE, null, ex); |
52 | - | } catch (javax.swing.UnsupportedLookAndFeelException ex) { |
52 | + | } catch (IllegalAccessException ex) { |
53 | - | java.util.logging.Logger.getLogger(MyFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); |
53 | + | java.util.logging.Logger.getLogger(MyFrame.class.getName()).log( |
54 | - | } |
54 | + | java.util.logging.Level.SEVERE, null, ex); |
55 | } catch (javax.swing.UnsupportedLookAndFeelException ex) { | |
56 | - | /* Create and display the form */ |
56 | + | java.util.logging.Logger.getLogger(MyFrame.class.getName()).log( |
57 | - | java.awt.EventQueue.invokeLater(new Runnable() { |
57 | + | java.util.logging.Level.SEVERE, null, ex); |
58 | } | |
59 | - | public void run() { |
59 | + | |
60 | - | MyFrame frame = new MyFrame(); |
60 | + | /* Create and display the form */ |
61 | - | frame.setLocationRelativeTo(null); |
61 | + | java.awt.EventQueue.invokeLater(new Runnable() { |
62 | - | frame.setVisible(true); |
62 | + | |
63 | - | } |
63 | + | public void run() { |
64 | - | }); |
64 | + | MyFrame frame = new MyFrame(); |
65 | - | } |
65 | + | frame.setLocationRelativeTo(null); |
66 | frame.setVisible(true); | |
67 | } | |
68 | - | /* Normally there is more stuff happening here |
68 | + | }); |
69 | - | * but this much will do for the sake of example |
69 | + | |
70 | ||
71 | private void runButtonActionPerformed(java.awt.event.ActionEvent evt) { | |
72 | - | for(int i=1; i<1000;i++) |
72 | + | /* |
73 | - | data.add(new String[]{"entry1", "value1", "value2", "value3"}); |
73 | + | * Normally there is more stuff happening here but this much will do for |
74 | - | |
74 | + | * the sake of example |
75 | - | SwingUtilities.invokeLater(new DataPreviewAction(data, tabs)); |
75 | + | |
76 | List<String[]> data = new LinkedList<String[]>(); | |
77 | - | |
77 | + | for (int i = 1; i < 1000; i++) |
78 | data.add(new String[] { "entry1", "value1", "value2", "value3" }); | |
79 | - | |
79 | + | |
80 | SwingUtilities.invokeLater(new DataPreviewAction(data, tabs)); | |
81 | } | |
82 | - | |
82 | + | |
83 | - | public DataPreviewAction(List<String[]> data, JTabbedPane comp){ |
83 | + | |
84 | ||
85 | private JTabbedPane contentHolder; | |
86 | private List<String[]> data; | |
87 | ||
88 | public DataPreviewAction(List<String[]> data, JTabbedPane comp) { | |
89 | this.contentHolder = comp; | |
90 | - | DefaultTableModel previewModel = new DefaultTableModel(){ |
90 | + | |
91 | } | |
92 | - | public boolean isCellEditable(int row, int column){ |
92 | + | |
93 | @Override | |
94 | - | }}; |
94 | + | |
95 | - | |
95 | + | DefaultTableModel previewModel = new DefaultTableModel() { |
96 | - | for(String[] datarow : data){ |
96 | + | |
97 | - | previewModel.addRow(Arrays.copyOf(datarow, datarow.length, Object[].class)); |
97 | + | public boolean isCellEditable(int row, int column) { |
98 | return false; | |
99 | - | |
99 | + | } |
100 | }; | |
101 | - | |
101 | + | |
102 | for (String[] datarow : data) { | |
103 | - | buttonPanel.add(new JButton("A button")); |
103 | + | previewModel.addRow(Arrays.copyOf(datarow, datarow.length, |
104 | - | buttonPanel.add(new JLabel("Some description for the awesome table below ")); |
104 | + | Object[].class)); |
105 | - | buttonPanel.add(new JButton("another button")); |
105 | + | |
106 | - | |
106 | + | |
107 | - | JScrollPane tablePanel = new JScrollPane(table); |
107 | + | |
108 | - | JPanel container = new JPanel(); |
108 | + | |
109 | - | container.setLayout(new BorderLayout()); |
109 | + | |
110 | - | container.add(buttonPanel,BorderLayout.NORTH); |
110 | + | buttonPanel.add(new JButton("A button")); |
111 | - | container.add(tablePanel,BorderLayout.CENTER); |
111 | + | buttonPanel.add(new JLabel( |
112 | "Some description for the awesome table below ")); | |
113 | buttonPanel.add(new JButton("another button")); | |
114 | ||
115 | JScrollPane tablePanel = new JScrollPane(table); | |
116 | JPanel container = new JPanel(); | |
117 | container.setLayout(new BorderLayout()); | |
118 | container.add(buttonPanel, BorderLayout.NORTH); | |
119 | container.add(tablePanel, BorderLayout.CENTER); | |
120 | contentHolder.addTab("Preview", container); | |
121 | contentHolder.validate(); | |
122 | contentHolder.repaint(); | |
123 | } | |
124 | } | |
125 | } |