Nie jest to jakieś eleganckie ale na szybko mogło by to wyglądać tak:
Kopiuj
package dotestow;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class test extends JFrame {
smiec3(){
initComponent();
}
private void initComponent(){
panel1.setLayout(new GridLayout(1,1));
mainPanel.setLayout(new FlowLayout());
panel1.add(button1);
mainPanel.add(panel1);
frame.setSize(new Dimension(100,100));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setEditable(false);
frame.setVisible(true);
frame.add(mainPanel);
frame.setTitle("Glowne Okno");
button1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
dialog.setSize(new Dimension(400,400));
dialog.setTitle("JDialog okno");
dPanel.setLayout(new GridLayout(20,1));
for(int i= 0;i<20;i++){
String s = String.valueOf(i).toString();
dPanel.add(button[i]=new JButton(s));
}
pane.setViewportView(dPanel);
dialog.add(pane);
dialog.setVisible(true);
}
});
}
private JButton button[] = new JButton[20];
private JPanel dPanel = new JPanel();
private JScrollPane pane = new JScrollPane();
private JDialog dialog = new JDialog();
private JFrame frame =new JFrame();
private JPanel mainPanel= new JPanel();
private JPanel panel1 = new JPanel();
private JButton button1= new JButton("Przycisk");
}
i wywołanie gdzieś tam:
Kopiuj
public class MainClass {
public static void main(String[] args) {
test s = new test();
}
}
Mam nadzieję ze to rozwiąże twoje problemy ^^
Chciał bym z tego miejsca pozdrowić mamę, tatę i brata i, i jeszcze psa! ;]
PS. Aha ja to pisałem w eclipse wiec musiał byś sobie to zaimportować do netBeans jakoś albo w 2 stronę z netBeans do eclipse (co wydaje mi się prostsze) ja zawsze robię sobie szablony w netBeans a później importuje 2 biblioteczki do eclipse i wklejam kod no i oczywiście tam już sobie nanoszę poprawki.