Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

radio button java swing

//In initialization code:
    ImageIcon leftButtonIcon = createImageIcon("images/right.gif");
    ImageIcon middleButtonIcon = createImageIcon("images/middle.gif");
    ImageIcon rightButtonIcon = createImageIcon("images/left.gif");

    b1 = new JButton("Disable middle button", leftButtonIcon);
    b1.setVerticalTextPosition(AbstractButton.CENTER);
    b1.setHorizontalTextPosition(AbstractButton.LEADING); //aka LEFT, for left-to-right locales
    b1.setMnemonic(KeyEvent.VK_D);
    b1.setActionCommand("disable");

    b2 = new JButton("Middle button", middleButtonIcon);
    b2.setVerticalTextPosition(AbstractButton.BOTTOM);
    b2.setHorizontalTextPosition(AbstractButton.CENTER);
    b2.setMnemonic(KeyEvent.VK_M);

    b3 = new JButton("Enable middle button", rightButtonIcon);
    //Use the default text position of CENTER, TRAILING (RIGHT).
    b3.setMnemonic(KeyEvent.VK_E);
    b3.setActionCommand("enable");
    b3.setEnabled(false);

    //Listen for actions on buttons 1 and 3.
    b1.addActionListener(this);
    b3.addActionListener(this);

    b1.setToolTipText("Click this button to disable "
                      + "the middle button.");
    b2.setToolTipText("This middle button does nothing "
                      + "when you click it.");
    b3.setToolTipText("Click this button to enable the "
                      + "middle button.");
    ...
}

public void actionPerformed(ActionEvent e) {
    if ("disable".equals(e.getActionCommand())) {
        b2.setEnabled(false);
        b1.setEnabled(false);
        b3.setEnabled(true);
    } else {
        b2.setEnabled(true);
        b1.setEnabled(true);
        b3.setEnabled(false);
    }
} 

protected static ImageIcon createImageIcon(String path) {
    java.net.URL imgURL = ButtonDemo.class.getResource(path);
    ...//error handling omitted for clarity...
    return new ImageIcon(imgURL);
}
Comment

PREVIOUS NEXT
Code Example
Java :: logical operators in java 
Java :: java replaceAll ignore case 
Java :: get year month day from date string java 
Java :: how to check the end of a string java 
Java :: compare two times in java 
Java :: intent pick action video android 
Java :: spinner get selected index 
Java :: android studio alert dialog box 
Java :: how to add element to end of array java 
Java :: android ask if system is in dark mode 
Java :: count occurrences of character in string java 8 
Java :: List into string java 
Java :: hide element selenium 
Java :: java regex 
Java :: abs in java 
Java :: java gitignore 
Java :: send data from service to activity class 
Java :: android sqlite select query 
Java :: exception in thread "main" java.lang.indexoutofboundsexception: index 1 out of bounds for length 1 
Java :: armstrong number in java 
Java :: find minimum number in java 
Java :: start async task android 
Java :: java logger with different colors 
Java :: linear search java 
Java :: how to find palindrome numbers in java 
Java :: quicksort for arraylist 
Java :: java list select field 
Java :: pyramid pattern program in java 
Java :: System.out.println("Hello world") 
Java :: java delete object 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =