Swing button

hi
i am writing swing event handling application in which i want write button event
which executes (run) different classes?
how to write button event ?
i write a public class that does not implement ActionListener interface why ?

which executes (run) different classes?I didnt understand this
how to write button event ?There are many ways to do it. The simple one is to implement ActionListener in your class and implement actionPerformed. While creating the button you must add an action listener.
public YourClass (){
button1 = new JButton ();
button1.addActionListener (this);
//Add the button to your frame
public void actionPerformed (ActionEvent ae) {
//Handle the event.
i write a public class that does not implement
ActionListener interface why ?You are the author of your code, not us. You tell us why or why not.

Similar Messages

  • Problem with java swing button and loop

    Problem with java swing button and loop
    I�m using VAJ 4.0. and I�m doing normal GUI application. I have next problem.
    I have in the same class two jswing buttons named start (ivjGStart) and stop (ivjGStop) and private static int field named Status where initial value is 0. This buttons should work something like this:
    When I click on start button it must do next:
    Start button must set disenabled and Stop button must set enabled and selected. Field status is set to 1, because this is a condition in next procedure in some loop. And then procedure named IzvajajNeprekinjeno() is invoked.
    And when I click on stop button it must do next:
    Start button must set enabled and selected and Stop button must set disenabled.
    Field status is set to 0.
    This works everything fine without loop �do .. while� inside the procedure IzvajajNeprekinjeno(). But when used this loop the start button all the time stay (like) pressed. And this means that a can�t stop my loop.
    There is java code, so you can get better picture:
    /** start button */
    public void gStart_ActionEvents() {
    try {
    ivjGStart.setEnabled(false);
    ivjGStop.setEnabled(true);
    ivjGStop.setSelected(true);
    getJTextPane1().setText("Program is running ...");
    Status = 1;
    } catch (Exception e) {}
    /** stop button */
    public void gStop_ActionEvents() {
    try {
    ivjGStart.setEnabled(true);
    ivjGStart.setSelected(true);
    ivjGStop.setEnabled(false);
    getJTextPane1().setText("Program is NOT running ...");
    Status = 0;
    } catch (Exception e) {
    /** procedure IzvajajNeprekinjeno() */
    public void IzvajajNeprekinjeno() {  //RunLoop
    try {
    int zamik = 2000; //delay
    do {
    Thread.sleep(zamik);
    PreberiDat(); //procedure
    } while (Status == 1);
    } catch (Exception e) {
    So, I'm asking what I have to do, that start button will not all the time stay pressed? Or some other aspect of solving this problem.
    Any help will be appreciated.
    Best regards,
    Tomi

    This is a multi thread problem. When you start the gui, it is running in one thread. Lets call that GUI_Thread so we know what we are talking about.
    Since java is task-based this will happen if you do like this:
    1. Button "Start" is pressed. Thread running: GUI_Thread
    2. Event gStart_ActionEvents() called. Thread running: GUI_Thread
    3. Method IzvajajNeprekinjeno() called. Thread running: GUI_Thread
    4. Sleep in method IzvajajNeprekinjeno() on thread GUI_Thread
    5. Call PreberiDat(). Thread running: GUI_Thread
    6. Check status. If == 1, go tho 4. Thread running: GUI_Thread.
    Since the method IzvajajNeprekinjeno() (what does that mean?) and the GUI is running in the same thread and the event that the Start button has thrown isn't done yet, the program will go on in the IzvajajNeprekinjeno() method forever and never let you press the Stop-button.
    What you have to do is do put either the GUI in a thread of its own or start a new thread that will do the task of the IzvajajNeprekinjeno() method.
    http://java.sun.com/docs/books/tutorial/uiswing/index.html
    This tutorial explains how to build a multi threaded gui.
    /Lime

  • How to position the Swing button on javaFx applet

    Hello,
    I am putting a swing button on javaFx page as:
    SwingButton {
                    text: "Go"
                    action: function() {
                        widgetManager.openDirectAlertId(homeBean.getAlert(1).getAlertId());
                }This button always appear on the top of the page.Now, i want to align this button to X and Y coordinates.
    I have two variable varX and varY, how can i bind this button to these coordinates?
    Thanks to reply
    Anuj

    Use translateX and translateY attributes:
                SwingButton {
                    text: "Go"
                    translateX: 50
                    translateY: 10
                    action: function() {
                        widgetManager.openDirectAlertId(homeBean.getAlert(1).getAlertId());
                }       

  • Best Practice Buttons? and Swing Button Sizes

    Hi,
    I am wondering what the best way to make a custom styled button was....
    Since I need my own style of button (width,height,background image, selected, clicked) I thought I would use Swing buttons with a Synth style. However, when I place swing buttons inside a CustomNode, all of the button widths, heights, x, y settings are discarded. I can understand the x/y being discarded as the component location should become relative and set by the wrapping CustomNode. I can also understand this because I can set the positions with translateX and translateY. However, I can't see how I can set a width and height of the swing button from inside the CustomNode.
    Can this be done?
    Alternatively, I don't mind using an alternative to the swing button however this is the only button I can see in JavaFX.
    Thanks for reading

    Ok, looks like I can wrap the button's inside a group, stage eta Node wrapper. Then I can preserve the button sizes and can produce relative/translatable positioning of the group/stage. This I understand and find to be a good feature. One thing that does concern me is that with the Swing button's - the Synth styles are not correctly applied. No matter what I do I can not get button text color to change. Changing the background mostly works but the text label styling is completely ignored.

  • [SOLVED] XFCE - Java Swing button theme?

    I'm running XFCE, and I notice that all Swing-based Java applications use the ugly Swing button theme. When I used GNOME 3, some of them would adapt to the GNOME button theme (and would look like they belonged on the system).
    Is this issue with XFCE, my current GTK theme (dorian), or Java, and how can I change this?
    Last edited by 2mac (2014-01-01 22:17:07)

    Thank you for the information.
    I followed the wiki by adding
    export _JAVA_OPTIONS="-Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel"
    to my ~/.bashrc file.
    To test, I launched the Minecraft launcher (one of the applications which does support style changes between desktops), and got back this information:
    Picked up _JAVA_OPTIONS: -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel
    Error parsing gtk-icon-sizes string: ''
    And it had no effect. Any ideas?
    Last edited by 2mac (2013-12-31 16:35:39)

  • Swing button PJC

    Hi All,
    I am trying to use Swing button PJC getting help from below website.
    http://forms.pjc.bean.over-blog.com/categorie-450786.html
    I am using forms 9i version not sure it is compatible for PJC?
    While running the form I am getting certificate notification after granting the permission form is not displaying the canvse.
    Please suggest.
    Thanks for your help.

    Sorry I got the information....
    Thanks for your help.

  • Adding a branchgroup to a live scene with swing buttons

    Hi, please have a look on the following code.
    I want to add "objects" in a live scene.
    I've planned to do this by attaching a new branchgroup
    to an existing alive structure.
    The code of the new branchgroup is in the action of a swing button.
    // method "addObject" called by the button
    private class addObject extends BranchGroup implements ActionListener {
    public void actionPerformed(ActionEvent event){
    BranchGroup obj = new BranchGroup ();
    // Creation of a sphere
    Sphere sphere = new Sphere (0.3f);
    System.out.println(sphere);
    obj.addChild (sphere);
    obj.addChild (this);
    System.out.println("add action");
    System.out.println(obj);
    // definition of the button
         private JButton ajout = new JButton("Ajout");
         JPanel p2 = new JPanel();
    ajout.addActionListener(new addObject());
    p2.add(ajout);
    // code to attach the branchgroup
         BranchGroup b2 = new addObject();
    System.out.println("br "+b2);
    objRoot.addChild(b2);
    objRoot.compile();
    return objRoot;
    But, the Sphere is not seen on the scene
    even if the action on the button seems to work.
    And if i do twice, i get this error :
    Exception occurred during event dispatching:
    javax.media.j3d.MultipleParentException: Group.addChild: child already has a parent
         at javax.media.j3d.GroupRetained.checkValidChild(GroupRetained.java:442)
         at javax.media.j3d.GroupRetained.addChild(GroupRetained.java:451)
         at javax.media.j3d.Group.addChild(Group.java:266)
         at applet3d.Scene3D$addObject.actionPerformed(Scene3D.java:588)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1450)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1504)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:378)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:250)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:216)
         at java.awt.Component.processMouseEvent(Component.java:3715)
         at java.awt.Component.processEvent(Component.java:3544)
         at java.awt.Container.processEvent(Container.java:1164)
         at java.awt.Component.dispatchEventImpl(Component.java:2593)
         at java.awt.Container.dispatchEventImpl(Container.java:1213)
         at java.awt.Component.dispatchEvent(Component.java:2497)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2216)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2125)
         at java.awt.Container.dispatchEventImpl(Container.java:1200)
         at java.awt.Window.dispatchEventImpl(Window.java:914)
         at java.awt.Component.dispatchEvent(Component.java:2497)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
    Anyone can help ?
    Thanks

    I've changed the code a bit.
    I don't have the exception anymore, and when i press the button, i really create instances of sphres, but they are not seen in the Scene.
    Any idea someone ?
    package applet3d;
    import java.awt.*;
    import java.awt.GraphicsConfiguration;
    import java.awt.event.*;
    import com.sun.j3d.utils.geometry.*;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.behaviors.mouse.*;
    import com.sun.j3d.utils.behaviors.keyboard.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import javax.swing.*;
    public class Scene3Db extends JFrame implements ActionListener, MouseListener {
         private static final long serialVersionUID = 1L;
         private SimpleUniverse su;
    private BranchGroup sceneBG, mainBG, shapeBG, objRoot;
    private TransformGroup mainTG, shapeTG, cameraTG;
    private BoundingSphere bounds;
    private Material material2;
    private static int mycount = 1;
    //declaration des elements du gui
    private JLabel etiq1;
    private JCheckBox couleur;
    //constructeur
    public Scene3Db() {
    Container contentPane = getContentPane();
    //BorderLayout bl = new BorderLayout();
    //setLayout(bl);
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
    Canvas3D c = new Canvas3D(config);
    contentPane.add("Center", c);
    JPanel p1 = new JPanel();
    p1.add(presentationPanel());
    contentPane.add("North", p1);
    JPanel p2 = new JPanel();
    JButton ajout = new JButton("Ajout");
    addObject addObjBG = new addObject();
    ajout.addActionListener(addObjBG);
    //objRoot.addChild(addObjBG); //pb !
    p2.add(ajout);
    contentPane.add("South", p2);
    SimpleUniverse su = new SimpleUniverse(c);
    BranchGroup scene = createSceneGraph(su);
    //scene.setCapability( BranchGroup.ALLOW_BOUNDS_READ );
    su.getViewingPlatform().setNominalViewingTransform();
    su.addBranchGraph(scene);
    addWindowListener( new WindowAdapter() {
    public void windowClosing(WindowEvent e) {System.exit(0);}});
    setSize(800,600); //Taille Fenetre
    show();
    repaint();
    //cr�ation du graphe de sc�ne
    public BranchGroup createSceneGraph(SimpleUniverse su) {
    //cr�ation d'un BG racine de l'arbre 3D
    //BranchGroup objRoot = new BranchGroup();
    objRoot = new BranchGroup();
    objRoot.setCapability( BranchGroup.ALLOW_PICKABLE_READ );
    objRoot.setCapability( BranchGroup.ALLOW_PICKABLE_WRITE );
    objRoot.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    objRoot.setCapability(BranchGroup.ALLOW_DETACH);
    objRoot.setCapability(Group.ALLOW_CHILDREN_READ);
    objRoot.setCapability(Group.ALLOW_CHILDREN_WRITE);
    objRoot.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    //cr�ation d'un bounds pour le fond et la lumi�re
    BoundingSphere bounds =
    new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
    Background bg = new Background(bgColor);
    bg.setApplicationBounds(bounds);
    objRoot.addChild(bg);
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
    DirectionalLight light1
    = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);
    BranchGroup sceneObj = new BranchGroup();
    //cr�ation d'un TG pour la gestion d'�chelle
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);
    objScale.setTransform(t3d);
    sceneObj.addChild(objScale);
    //cr�ation d'un TG pour permettre la modification des objets visuels
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objScale.addChild(objTrans);
    MouseRotate myMouseRotate = new MouseRotate();
    myMouseRotate.setTransformGroup(objTrans);
    myMouseRotate.setSchedulingBounds(new BoundingSphere());
    sceneObj.addChild(myMouseRotate);
    MouseTranslate myMouseTranslate = new MouseTranslate();
    myMouseTranslate.setTransformGroup(objTrans);
    myMouseTranslate.setSchedulingBounds(new BoundingSphere());
    sceneObj.addChild(myMouseTranslate);
    MouseZoom myMouseZoom = new MouseZoom();
    myMouseZoom.setTransformGroup(objTrans);
    myMouseZoom.setSchedulingBounds(new BoundingSphere());
    sceneObj.addChild(myMouseZoom);
    //Canvas3D c = new Canvas3D(null);
    //PickHighlightBehavior pickBeh = new
    //PickHighlightBehavior(c, objRoot, bounds);
    BranchGroup b2 = new addObject();
    objRoot.addChild(b2);
    //System.out.println("br "+b2);
    objRoot.addChild(sceneObj);
    //objRoot.addChild(b2);
    objRoot.compile();
    return objRoot;
    public JPanel presentationPanel() {
         JPanel panel1 = new JPanel();
    etiq1 = new JLabel
    ("Modelisation d'un environnement naturel en 3D / � 2005 cnam ubo");
    panel1.add(etiq1);
    return panel1;
    //fonction ajout d'objet
    private class addObject extends BranchGroup implements ActionListener {
    private addObject () {
    this.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
    public void actionPerformed(ActionEvent event){
    BranchGroup obj = new BranchGroup ();
    // Cr�ation d'une sph�re
    Sphere sphere = new Sphere (0.3f, Sphere.GENERATE_NORMALS, 20);
    System.out.println(sphere);
    Transform3D sphereRandromTransform = new Transform3D ();
    sphereRandromTransform.setTranslation(new Vector3d(randomCoord(),randomCoord(),randomCoord()));
    TransformGroup sphereTG = new TransformGroup (sphereRandromTransform);
    sphereTG.addChild(sphere);
    obj.addChild(sphereTG);
    this.addChild(obj);
    System.out.println("action ajout");
    System.out.println(obj);
    private double randomCoord () {
    double coord = Math.random();
    return coord>=0.5?-coord*5:coord*5;
    public void mouseClicked( MouseEvent e ) {
    public void mouseEntered( MouseEvent e ) {
    public void mouseExited( MouseEvent e ) {
    public void mousePressed( MouseEvent e ) {
    // if (e.getSource()==reset) {
    //setNominalPositionAndOrientation();
    public void mouseReleased( MouseEvent e ) {
    //mode = STILL;
    public void actionPerformed(ActionEvent e) {
    Object target = e.getSource();
    if (target == couleur) {
    if (couleur.isSelected()){
    //scene.pickBeh;
    public static void main(String[] args) {
         try {
    //D�finition du type d'affichage boite de dialogue
    //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
              } catch (Exception exc) {
    System.err.println("Erreur de chargement L&F: " + exc);
    new Scene3Db();
    }

  • Swing button to insert row in displayed table records set

    Hi,
    I have been trying to insert custom row by pressing button in Swing form, this row should be displayed as last record in the records set fetched from table shown in the Swing form, can I have a help on this.
    cheers.

    Hi,
    the way you do this with ADF is to create an action binding for the ViewObject's CreateInsert operation. You do this in the pageDef file. Then from teh button, you use the panelBinding object to execute that method. Get access to the iterator binding and fill in the infromation you want to add. Then commit the change.
    If i find time I'll blog an example at orablogs.oracle.com/fnimphius
    Frank

  • How to assign the enter pressing to the button click event of swing button?

    Hello to all you pro's,
    I can't find how to make my button a default button so it will respond to an enter press.
    any help will be most appreciated.
    thanks in advanced.

    get the RootPane and call setDefaultButton on it. Something like so:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    class SwingFu2 extends JPanel
        private JButton buttonOK = new JButton("OK");
        private JButton buttonCancel = new JButton("Cancel");
        private JTextField textfield = new JTextField(12);
        private JFrame frame;
        SwingFu2(JFrame frame)
            this.frame = frame;
            ActionListener buttonActionListener = new ButtonActionListener();
            buttonOK.addActionListener(buttonActionListener);
            buttonCancel.addActionListener(buttonActionListener);
            add(textfield);
            add(buttonOK);
            add(buttonCancel);
            frame.getRootPane().setDefaultButton(buttonOK);
        private class ButtonActionListener implements ActionListener
            @Override
            public void actionPerformed(ActionEvent e)
                String command = e.getActionCommand();
                if (command.equalsIgnoreCase("OK"))
                    System.out.println("OK pressed");
                    System.out.print("Text in textfield: ");
                    System.out.println(textfield.getText());
                else if (command.equalsIgnoreCase("Cancel"))
                    frame.dispose();
        private static void createAndShowUI()
            JFrame frame = new JFrame("SwingFu1");
            frame.getContentPane().add(new SwingFu2(frame));
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args)
            java.awt.EventQueue.invokeLater(new Runnable()
                public void run()
                    createAndShowUI();
    }

  • Any swing buttons??

    Does anyone know of any swing libraries that contain pre-fab buttons? I'm looking for button's to use as "New" "Save" "Open" those type..
    Thanks
    Adam

    No, I don't. But they are so easy to make (JButton okButton = new JButton("OK");, etc.) that such a library would be pretty unnecessary.

  • Swing buttons

    I have this swing ui that i have been working on, every thing is working ok now except the buttons come out - one on top of another instead of side by side.
    how can i make them show up side by side?
    thanks GJ

    by the way here is the code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.util.Enumeration;
    import javax.swing.*;
      public class Translator1 extends JApplet implements ActionListener {
        private String myName;
        private JTextField nameField;
        private JTextArea status;
        private String newline;
        public void init() {
         this.setBackground(Color.lightGray);
         GridBagLayout gridBag = new GridBagLayout();
            GridBagConstraints c = new GridBagConstraints();
            getContentPane().setLayout(gridBag);
            JLabel receiverLabel = new JLabel("Type Text Here:", Label.RIGHT);
            gridBag.setConstraints(receiverLabel, c);
         this.getContentPane().add(receiverLabel);
            nameField = new JTextField(getParameter("TRANSLATIONTEXT"), 30);
            c.fill = GridBagConstraints.HORIZONTAL;
         c.gridwidth = GridBagConstraints.REMAINDER;
            gridBag.setConstraints(nameField, c);
         this.getContentPane().add(nameField);
            nameField.addActionListener(this);
            JButton button = new JButton("Translate Text");  //TEXT BUTTONS
            c.anchor = GridBagConstraints.WEST;
         c.fill = GridBagConstraints.NONE;
            gridBag.setConstraints(button, c);
         this.getContentPane().add(button);
         button.addActionListener(this);
         JButton button1 = new JButton("Add Translations");
            c.anchor = GridBagConstraints.WEST;
            gridBag.setConstraints(button1, c);
         this.getContentPane().add(button1);
         JButton button2 = new JButton("List Translations");
            c.anchor = GridBagConstraints.WEST;
            gridBag.setConstraints(button2, c);
         this.getContentPane().add(button2);
         JButton button3 = new JButton("Clear Text");
         c.gridwidth = GridBagConstraints.REMAINDER;      //THIS ENDS THE ROW
         c.anchor = GridBagConstraints.WEST;
            gridBag.setConstraints(button3, c);
         this.getContentPane().add(button3);
            status = new JTextArea(5, 60);                    // THE LARGE NON-EDITABLE TEXT AREA
            status.setEditable(false);
            c.anchor = GridBagConstraints.CENTER;           //reset to the default
         status.setBackground(Color.white);              // color
            c.fill = GridBagConstraints.BOTH;               //make this big
            c.weightx = 1.0;
            c.weighty = 1.0;
            gridBag.setConstraints(status, c);
         this.getContentPane().add(status);
         newline = System.getProperty("line.separator");
        public void actionPerformed(ActionEvent event) {
            String translationText = nameField.getText();     
         nameField.setText("");
            status.append("The Text you want to translate is: " + translationText + "." + newline);
        public Insets getInsets() {
            return new Insets(30,30,30,30);  
       public void paint(Graphics g) {
           super.paint( g );
           g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
    }

  • How do i place image instead of text  in swing button  ?

    Hi
    I need to place image in place of text in button i.e in place of button name i need to display image.
    Please tell me how to do this.......

    You'll need to use CSS floats.
    .floatLt {
         float:left;
         width:auto;
    HTML:
    <div class="floatLt">
    YOUR LOGO IMG HERE
    </div>
    <ul id="MenuBar1" class="MenuBarHorizontal floatLt">
    YOUR MENU GOES HERE
    </ul>
    Coding skills are essential to using DW.  Learn HTML & CSS first.  DW will be much easier.
    HTML, CSS & Web Design Theory Tutorials -
    http://w3schools.com/
    http://www.csstutorial.net/
    http://phrogz.net/css/HowToDevelopWithCSS.html
    http://webdesign.tutsplus.com/sessions/web-design-theory/
    Nancy O.

  • Opening  Webpage using Swing Button Event

    I am having one JButton. If they press the button i want to open a webpage how to achieve this. please help me . its very urgent

    Works for me on Windows XP.
    What OS are you using?
    Can you post some code.

  • 3 Customizing Swing Buttons --- Colors etc

    Hi Java Experts
    I have a quick question about customizing JButton Color
    --- naturally I know to simply setBackground(Color c);
    QUESTION 1:
    However how do you change the color when the button is clicked
    QUESTION 2:
    how do you change the type of border around JButton from etched to Raised ?
    QUESTION 3:
    How do change the color of the JComboBox -- from Gray to something else ?
    QUESTION 4:
    How do I customize the color of the JScrollBar
    Thanks in advance
    Stephen

    Hi Java Experts
    I have a quick question about customizing JButton
    Color
    --- naturally I know to simply setBackground(Color c);
    QUESTION 1:
    However how do you change the color when the button is
    clicked
    yourbutton.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
                     yourbutton.setBackground(Color.pink); // :P u like pink?
    });>
    QUESTION 2:
    how do you change the type of border around JButton
    from etched to Raised ?
    yourbutton.setBorder(BorderFactory.createRaisedBevelBorder()); // raised, obviously :P
    yourbutton.setBorder(BorderFactory.createEtchedBorder()); // etched :)
    QUESTION 3:
    How do change the color of the JComboBox -- from Gray
    to something else ? yourjcombobox.setBackground(Color.black);
    yourjcombobox.setForeground(Color.white); // the color of the text pretty much :)
    >
    QUESTION 4:
    How do I customize the color of the JScrollBar
    yourjscrollbar.setBackground(Color.pink); // u like it dont u?>
    Thanks in advance
    Stephen Ivo

  • Swing buttons -- synchronous vs. asychronous

    I'll be brief...
    I need to be able to create a method of the form:
    result = getUserInput(String choices[]);
    that presents the user with a JComboBox of choices, and an OK button, and when they push the button, the current index of the JComboBox is returned. The method does NOT return until the OK button has been pushed.
    This method is called from other classes, as a utility method.
    I won't go into why I need it done this way, but I do. Is there any way to do this? Because with installing an ActionListener for the button, I don't see how it can be done... It seems that the method above would only be able to put the buttons in place, then return, and wait for the ActionListener to be invoked. But this means the method above can't return the user's selection after they've pushed the button. That would have to be passed to the caller using some other message-passing mechanism.
    Is there any way to do what I want to do?
    -Vern

    D'oh! Ignore my question. I had posted the same question earlier, but couldn't find it... [Still don't know why I couldnt' find it, but I found it now, by clicking on my username.]
    Sorry about that.

Maybe you are looking for