śmierc_na_drodze dzięki CI bardzo za poprawke!!! Wszystko gra! Chciałbym dodac jeszcze do tego edytora obsługę czcionek, możliwośc zmiany kroju i wielkości, napisałem cos takiego:
/*
* FCzcionka.java
*
* Created on 2 czerwiec 2008, 18:05
*/
package edytor;
import java.awt.Font;
/**
*
* @author Michał
*/
public class FCzcionka extends javax.swing.JDialog {
private FEdytor edytor;
private Font[] czcionki;
/** Creates new form FCzcionka */
public FCzcionka(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
java.awt.GraphicsEnvironment e =
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment();
czcionki = e.getAllFonts();
java.util.Vector v = new java.util.Vector();
for (int i = 0; i < czcionki.length; i++)
v.add(czcionki[i].getName());
jList1.setListData(v);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
jLabel1 = new javax.swing.JLabel();
jSpinner1 = new javax.swing.JSpinner();
jLabel2 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
getContentPane().setLayout(null);
jList1.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
jScrollPane1.setViewportView(jList1);
getContentPane().add(jScrollPane1);
jScrollPane1.setBounds(10, 30, 200, 150);
jLabel1.setText("Krój czcionki:");
getContentPane().add(jLabel1);
jLabel1.setBounds(10, 10, 150, 14);
jSpinner1.addAncestorListener(new javax.swing.event.AncestorListener() {
public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
}
public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
jSpinner1AncestorAdded(evt);
}
public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
}
});
getContentPane().add(jSpinner1);
jSpinner1.setBounds(300, 90, 40, 20);
jLabel2.setText("Wielkosc czcionki");
getContentPane().add(jLabel2);
jLabel2.setBounds(280, 60, 90, 14);
jButton1.setText("OK");
getContentPane().add(jButton1);
jButton1.setBounds(225, 200, 70, 23);
jButton2.setText("Anuluj");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
getContentPane().add(jButton2);
jButton2.setBounds(310, 200, 65, 23);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-400)/2, (screenSize.height-271)/2, 400, 271);
}// </editor-fold>
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
dispose();
}
private void jSpinner1AncestorAdded(javax.swing.event.AncestorEvent evt) {
int c = jList1.getSelectedIndex();
if (c == -1) return; // nic nie wybrano
// nasz spinner operuje na liczbach, jego model to SpinnerNumberModel
javax.swing.SpinnerNumberModel m =
(javax.swing.SpinnerNumberModel) jSpinner1.getModel();
int rozm = m.getNumber().intValue();
// wyprowadzamy nową czcionkę ze stylem 0 i zadanym rozmiarem
java.awt.Font f = czcionki[c].deriveFont(0,rozm);
edytor.jtaEdycja.setFont(f); // ustawiamy nową czcionkę w oknie edycji
setVisible(false);
dispose();
edytor.jtaEdycja.requestFocus(); // TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JList jList1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSpinner jSpinner1;
// End of variables declaration
}
Jak kompiluje w netBeansie niby wszytsko jest ok, ale w JCreatorze wystepują błędy:
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Process completed.
P.S. Dlaczego w NetBeansie po skompilowaniu i uruchomieniu projektu wyskakuje w okienku Output BUILD SUCCESSFUL a nie widac efektu mojej pracy?