Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Java: GUI и Java FX приложения > После установки action'a не видно текста на кнопке


Автор: Royan 12.8.2008, 23:37
Делаю вот так:
Код

package test;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;

public class DialogBug extends JFrame {

    public static void main(String[] args) {
    final DialogBug db = new DialogBug();
    JButton jbut = new JButton("New Dialog");
    jbut.setAction(new AbstractAction(){
        public void actionPerformed(ActionEvent e) {
        }});
    db.add(jbut);
    db.pack();
    db.setVisible(true);
    }
}


Вопрос: почему не видно текста?

Автор: AlCapone 13.8.2008, 02:39
The Action interface provides a useful extension to the ActionListener  interface in cases where the same functionality may be accessed by several controls.

In addition to the actionPerformed method defined by the ActionListener interface, this interface allows the application to define, in a single place:

    !!!!!!!!!!!!!!!!!!!!!!!!* One or more text strings that describe the function. These strings can be used, for example, to display the flyover text for a button or to set the text in a menu item.!!!!!!!!!!!!!!!
    * One or more icons that depict the function. These icons can be used for the images in a menu control, or for composite entries in a more sophisticated user interface.
    * The enabled/disabled state of the functionality. Instead of having to separately disable the menu item and the toolbar button, the application can disable the function that implements this interface. All components which are registered as listeners for the state change then know to disable event generation for that item and to modify the display accordingly.
ну собственно код, который показывает строку с использованием AbstractAction
Код

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
public class testFrame extends JFrame {
    public static void main(String[] args) 
    {
    final testFrame db = new testFrame();
    JButton jbut = new JButton("New Dialog");
    modAbstractAction mAA=new modAbstractAction();
    mAA.putValue(AbstractAction.NAME,jbut.getText());
    jbut.setAction(mAA);
    db.add(jbut);
    db.pack();
    db.setVisible(true);
    }
}
class modAbstractAction extends AbstractAction
{
    public void actionPerformed(ActionEvent e) 
    {
    }
}
 
надеюсь,что помогло smile 

Автор: skif18 14.8.2008, 14:45
Код

jbut.setText("New Dialog");

и Усе....

Автор: Keyo 14.8.2008, 15:43
А почему никто не догадался тупо заглянуть в ман?

Код

package test;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;

public class DialogBug extends JFrame {
    public static void main(String[] args) {
    final DialogBug db = new DialogBug();
    JButton jbut = new JButton(new AbstractAction("New Dialog") {

            public void actionPerformed(ActionEvent e) {
                System.out.println("actionPerformed");
            }
        });
    
    db.add(jbut);
    db.pack();
    db.setVisible(true);
    }
}

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)