Disabling an inherited JButton

Dear all,
I have 2 child classes (ChildPanel1 & ChildPanel2) that extend ParentPanel. ParentPanel has a JButton component coupled with an accessor method toggleButton() to enable/disable the button.
I currently enable/disable the button by calling toggleButton() twice, once on the ChildPanel1 instance and then again on the ChildPanel2 instance. I'd like to be able to organise things so that I could enable/disable the button on all the instances of all the classes that extend ParentPanel with one call.
How can I do this?
Cheers!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ButtonTest {
    public class ParentPanel extends JPanel {
        protected JPanel buttonPanel;
        protected boolean enabled;
        protected JButton button1;
        public void toggleButton() {
            button1.setEnabled(enabled);
            if (enabled)
                enabled = false;
            else
                enabled = true;
        public ParentPanel(String title) {
            super(new BorderLayout());
            enabled = false;
            button1 = new JButton("Button 1");
            buttonPanel = new JPanel();
            buttonPanel.add(button1);
            setLayout(new BorderLayout());
            add(buttonPanel, BorderLayout.SOUTH);
    public class ChildPanel1 extends ParentPanel {
        public ChildPanel1() {
            super("Panel 1");
            JTextArea ta = new JTextArea();
            JScrollPane scroll = new JScrollPane();
            scroll.getViewport().add(ta);
            add(scroll, BorderLayout.CENTER);
    public class ChildPanel2 extends ParentPanel {
        protected JList myList;
        public ChildPanel2() {
            super("Panel 2");
            myList = new JList(new String[] { "item 1", "item 2" });
            JScrollPane ps = new JScrollPane();
            ps.getViewport().add(myList);
            JButton button2 = new JButton("Button 2");
            buttonPanel.add(button2);
            add(ps, BorderLayout.CENTER);
    public static void main(String argv[]) {
        JFrame frame = new JFrame("Button Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(370, 330);
        JPanel mainPanel = new JPanel(new BorderLayout());
        ButtonTest myTest = new ButtonTest();
        final ChildPanel1 panel1 = myTest.new ChildPanel1();
        final ChildPanel2 panel2 = myTest.new ChildPanel2();
        JTabbedPane jtp = new JTabbedPane();
        jtp.addTab("Tab 1", panel1);
        jtp.addTab("Tab 2", panel2);
        JButton disableButton = new JButton(new AbstractAction(
                "Toggle button 1") {
            public void actionPerformed(ActionEvent e) {
                panel1.toggleButton();
                panel2.toggleButton();
        mainPanel.add(disableButton, BorderLayout.SOUTH);
        mainPanel.add(jtp, BorderLayout.CENTER);
        frame.setContentPane(mainPanel);
        frame.pack();
        frame.show();
}

I've added another button to your test class that calls LoadSurfacesAction.getLoadSurfaceAction().setEnabled(false) when it's pressed. Once this method is invoked, LoadSurfacesAction.getLoadSurfaceAction().isEnabled does return false, however the button remains enabled.
Am I missing something?
Cheers!import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
public class TestClass {
    public static class LoadSurfacesAction extends AbstractAction {
        private static LoadSurfacesAction theInstance;
        private static final Action DEFAULT_ACTION = new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("Default load surfaces action called");
        private static Action theDelegate = DEFAULT_ACTION;
        public static Action getLoadSurfaceAction() {
            if (theInstance == null) {
                theInstance = new LoadSurfacesAction();
            return theInstance;
        public static void setAction(Action anAction) {
            theDelegate = anAction;
        public void actionPerformed(ActionEvent e) {
            theDelegate.actionPerformed(e);
    public class LoadVolPanel extends JPanel {
        protected JPanel buttonPanel;
        public LoadVolPanel(String title) {
            super(new BorderLayout());
            setBorder(new CompoundBorder(new TitledBorder(new EtchedBorder(),
                    title), new EmptyBorder(3, 5, 3, 5)));
            JButton loadButton = new JButton("Load surfaces");
            loadButton.setMnemonic('L');
            loadButton.addActionListener(LoadSurfacesAction
                    .getLoadSurfaceAction());
            buttonPanel = new JPanel();
            buttonPanel.add(loadButton);
            setLayout(new BorderLayout());
            add(buttonPanel, BorderLayout.SOUTH);
    public class LogPanel extends LoadVolPanel {
        public LogPanel() {
            super("Log");
            JTextArea ta = new JTextArea();
            ta.setLineWrap(true);
            ta.setWrapStyleWord(true);
            ta.setEditable(false);
            ta.append("The Load Surfaces button below kicks off\n");
            ta.append("a shell script on a unix box\n");
            ta.append("Output from the script appears here.\n");
            JScrollPane scroll = new JScrollPane();
            scroll.getViewport().add(ta);
            add(scroll, BorderLayout.CENTER);
    public class LoadPanel extends LoadVolPanel {
        protected JList securitiesList;
        public final int VISIBLE_ROWS = 12;
        public LoadPanel() {
            super("Codes");
            securitiesList = new JList(new String[] { "item 1", "item2" });
            securitiesList
                    .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            securitiesList.setLayoutOrientation(JList.VERTICAL_WRAP);
            securitiesList.setVisibleRowCount(VISIBLE_ROWS);
            JScrollPane ps = new JScrollPane();
            ps.getViewport().add(securitiesList);
            JButton refreshButton = new JButton("Refresh Securities List");
            buttonPanel.add(refreshButton);
            add(ps, BorderLayout.CENTER);
    public static void main(String argv[]) {
        JFrame frame = new JFrame("Load Volatility");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(370, 330);
        JPanel mainPanel = new JPanel();
        JPanel buttonPanel = new JPanel();
        mainPanel.setLayout(new BorderLayout());
        TestClass myTest = new TestClass();
        JPanel logPanel = myTest.new LogPanel();
        LoadPanel loadPanel = myTest.new LoadPanel();
        JTabbedPane jtp = new JTabbedPane();
        jtp.addTab("Load Volatility", loadPanel);
        jtp.addTab("Log", logPanel);
        mainPanel.add(jtp, BorderLayout.CENTER);
        LoadSurfacesAction.getLoadSurfaceAction().setEnabled(false);
        JButton changeActionButton = new JButton(new AbstractAction(
                "change action") {
            public void actionPerformed(ActionEvent e) {
                LoadSurfacesAction.setAction(new AbstractAction() {
                    public void actionPerformed(ActionEvent e) {
                        System.out
                                .println("Modified load surfaces action called");
        JButton disableButton = new JButton(new AbstractAction(
                "disable load button") {
            public void actionPerformed(ActionEvent e) {
                LoadSurfacesAction.getLoadSurfaceAction().setEnabled(false);
                System.out
                        .println("LoadSurfacesAction.getLoadSurfaceAction().isEnabled returned: "
                                + LoadSurfacesAction.getLoadSurfaceAction()
                                        .isEnabled());
        buttonPanel.add(changeActionButton);
        buttonPanel.add(disableButton);
        mainPanel.add(buttonPanel, BorderLayout.SOUTH);
        frame.setContentPane(mainPanel);
        frame.pack();
        frame.show();
}

Similar Messages

  • Assigning an ActionListener to an inherited JButton

    Dear all,
    I have a base JPanel class with a button, a border and not much else. This class is extended by 2 other classes in my application.
    I needed a means of associating an action with the button in my application's main class, so I added a static method addButtonListener to the base class, assuming that once I invoked this, the button would be 'activated' in all the panels inheriting from my base class. addButtonListener() simply invokes the button's addActionListener() method.
    Unfortunately this doesn't work, the ActionListener only gets linked to the button in one of the child classes (the first one that's instantiated).
    What's going on? The code for the base class is below...
    import java.awt.BorderLayout;
    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    import javax.swing.border.CompoundBorder;
    import javax.swing.border.EmptyBorder;
    import javax.swing.border.EtchedBorder;
    import javax.swing.border.TitledBorder;
    public class LoadVolPanel extends JPanel {
         protected JPanel buttonPanel;
         protected static JButton loadButton;
         public static void addButtonListener(ActionListener a) {
              loadButton.addActionListener(a);
         public LoadVolPanel(String title) {
              super();
              setBorder(new CompoundBorder(
                        new TitledBorder(new EtchedBorder(), title), new EmptyBorder(3,
                                  5, 3, 5)));
              loadButton = new JButton("Load surfaces");
              loadButton.setMnemonic('L');
              buttonPanel = new JPanel();
              buttonPanel.add(loadButton);
              setLayout(new BorderLayout());
              add(buttonPanel, BorderLayout.SOUTH);
    }

    I apologise for the amount of the code I've posted but it does compile, and will hopefully show you what I'm trying to do.
    I would like:
    - the Load button to appear at the bottom of each tab in the parent JTabbedPane;
    - the Load button perform the same action in all panes;
    - to be able to assign an action to the Load button from the main class.
    Cheers!
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    public class TestClass {
         public class LoadVolPanel extends JPanel {
              protected JPanel buttonPanel;
              protected JButton loadButton;
              public void AddButtonListener(ActionListener a) {
                   loadButton.addActionListener(a);
              public LoadVolPanel(String title) {
                   super();
                   setBorder(new CompoundBorder(new TitledBorder(new EtchedBorder(),
                             title), new EmptyBorder(3, 5, 3, 5)));
                   loadButton = new JButton("Load surfaces");
                   loadButton.setMnemonic('L');
                   buttonPanel = new JPanel();
                   buttonPanel.add(loadButton);
                   setLayout(new BorderLayout());
                   add(buttonPanel, BorderLayout.SOUTH);
         public class LogPanel extends LoadVolPanel {
              public LogPanel() {
                   super("Log");
                   JTextArea ta = new JTextArea();
                   ta.setLineWrap(true);
                   ta.setWrapStyleWord(true);
                   ta.setEditable(false);
                   ta.append("The Load Surfaces button below kicks off\n");
                   ta.append("a shell script on a unix box\n");
                   ta.append("Output from the script appears here.\n");
                   JScrollPane scroll = new JScrollPane();
                   scroll.getViewport().add(ta);
                   add(scroll, BorderLayout.CENTER);
         public class LoadPanel extends LoadVolPanel {
              protected JList securitiesList;
              public final int VISIBLE_ROWS = 12;
              private JTabbedPane tabbedPane;
              private CheckListCell[] volCodes = { new CheckListCell("AMP"),
                        new CheckListCell("ALN"), new CheckListCell("ANN"),
                        new CheckListCell("ANZ"), new CheckListCell("ASX"),
                        new CheckListCell("AXA"), new CheckListCell("BNB"),
                        new CheckListCell("BIL"), new CheckListCell("BSL"),
                        new CheckListCell("CBA"), new CheckListCell("CML"),
                        new CheckListCell("CSR"), new CheckListCell("DJS"),
                        new CheckListCell("FOA"), new CheckListCell("FXJ"),
                        new CheckListCell("GNS"), new CheckListCell("GPT"),
                        new CheckListCell("IAG"), new CheckListCell("JHX"),
                        new CheckListCell("LEI"), new CheckListCell("MAP"),
                        new CheckListCell("MBL"), new CheckListCell("MIG"),
                        new CheckListCell("NAB"), new CheckListCell("NWS"),
                        new CheckListCell("NWSLV"), new CheckListCell("ORG"),
                        new CheckListCell("OST"), new CheckListCell("PBG"),
                        new CheckListCell("PBL"), new CheckListCell("PMN"),
                        new CheckListCell("QAN"), new CheckListCell("RIN"),
                        new CheckListCell("RIO"), new CheckListCell("SEV"),
                        new CheckListCell("SGB"), new CheckListCell("SHL"),
                        new CheckListCell("SSX"), new CheckListCell("STO"),
                        new CheckListCell("TAH"), new CheckListCell("TCL"),
                        new CheckListCell("TLS"), new CheckListCell("VBA"),
                        new CheckListCell("WBC"), new CheckListCell("WDC"),
                        new CheckListCell("WMR"), new CheckListCell("WOW"),
                        new CheckListCell("WPL"), new CheckListCell("WSF"),
                        new CheckListCell("ZFX"), new CheckListCell("CCL"), };
              public LoadPanel() {
                   super("Codes");
                   securitiesList = new JList(volCodes);
                   CheckListCellRenderer renderer = new CheckListCellRenderer();
                   securitiesList.setCellRenderer(renderer);
                   securitiesList
                             .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                   securitiesList.setLayoutOrientation(JList.VERTICAL_WRAP);
                   securitiesList.setVisibleRowCount(VISIBLE_ROWS);
                   JScrollPane ps = new JScrollPane();
                   ps.getViewport().add(securitiesList);
                   JButton refreshButton = new JButton("Refresh Securities List");
                   buttonPanel.add(refreshButton);
                   add(ps, BorderLayout.CENTER);
         public final class CheckListCell {
              private String name;
              private boolean selected;
              public CheckListCell(String name) {
                   this.name = name;
                   selected = false;
              public String getName() {
                   return this.name;
              public void setSelected(boolean selected) {
                   this.selected = selected;
              public void invertSelected() {
                   selected = !selected;
              public boolean isSelected() {
                   return selected;
              public String toString() {
                   return name;
         public final class CheckListener implements MouseListener, KeyListener {
              private LoadPanel parent;
              private JList securitiesList;
              public CheckListener(LoadPanel parentPanel) {
                   parent = parentPanel;
                   securitiesList = parentPanel.securitiesList;
              public void mouseClicked(MouseEvent e) {
                   int index = securitiesList.locationToIndex(e.getPoint());
                   if (index == securitiesList.getSelectedIndex())
                        doCheck();
              public void mousePressed(MouseEvent e) {
              public void mouseReleased(MouseEvent e) {
              public void mouseEntered(MouseEvent e) {
              public void mouseExited(MouseEvent e) {
              public void keyPressed(KeyEvent e) {
                   if (e.getKeyChar() == ' ')
                        doCheck();
              public void keyTyped(KeyEvent e) {
              public void keyReleased(KeyEvent e) {
              private void doCheck() {
                   int index = securitiesList.getSelectedIndex();
                   if (index >= 0) {
                        CheckListCell cell = (CheckListCell) securitiesList.getModel()
                                  .getElementAt(index);
                        cell.invertSelected();
                        securitiesList.repaint();
         public class CheckListCellRenderer extends JCheckBox implements
                   ListCellRenderer {
              private Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
              public CheckListCellRenderer() {
                   setOpaque(true);
                   setBorder(noFocusBorder);
              public Component getListCellRendererComponent(JList list, Object value,
                        int index, boolean isSelected, boolean cellHasFocus) {
                   if (value != null)
                        setText(value.toString());
                   setBackground(isSelected ? list.getSelectionBackground() : list
                             .getBackground());
                   setForeground(isSelected ? list.getSelectionForeground() : list
                             .getForeground());
                   CheckListCell data = (CheckListCell) value;
                   setSelected(data.isSelected());
                   setFont(list.getFont());
                   setBorder((cellHasFocus) ? UIManager
                             .getBorder("List.focusCellHighlightBorder") : noFocusBorder);
                   return this;
         public static void main(String argv[]) {
              JFrame frame = new JFrame("Load Volatility");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setSize(370, 330);
              TestClass myTest = new TestClass();
              JPanel logPanel = myTest.new LogPanel();
              LoadPanel loadPanel = myTest.new LoadPanel();
              JTabbedPane jtp = new JTabbedPane();
              jtp.addTab("Load Volatility", loadPanel);
              jtp.addTab("Log", logPanel);
              frame.getContentPane().add(jtp);
              frame.pack();
              frame.show();
    }

  • Disable Inheritance on folder - Full permissions unable to rename

    I've got a document library with a couple folders inside. One of the folders I've disabled the inheritance of permission and provided a test user full control of the folder. They can add/delete files inside the folder but they're not able to rename the
    folder itself, it tells them access is denied. Is this by design? Any way around it?

    Hi,
    Still not able to reproduce so you need to check below points:
    1. Check event viewer in case any log entry is there:
    2. Also make below changes in web app your web.config file:
    Call stack =true and customerror mode = "Off
    Let us know if you find anything there
    Hemendra: "Yesterday is just a memory,Tomorrow we may never see"
    Whenever you see a reply and if you think is helpful, click "Vote As Helpful"! And whenever you see a reply
    being an answer to the question of the thread, click "Mark As Answer
    Changed both items in the web.config, performed the action again and got access denied. Don't see anything different in the ULS and don't see anything in the event viewer...
    You cant duplicate this? Are you attempting it as a farm/site admin? I've got just a regular user (User1) that I assigned full control to a doc library... 3 folders (A,B,C) inside the doc library. Disabled permissions inheritance on folder A and provided
    User1 full control. Folder B and C are left alone.
    User1 can modify contents inside of Folder A,B and C. Can add and deleted folders, other than A. It can rename the folders B and C, but get access denied on folder A.

  • Windows Server 2012 R2 robocopy not copying inherited directory permission from source file server to destination ?

    Can anyone here please help me with Robocopy on Windows Server 2012 R2 to copy the file server content from \\OldFileServer\Data share into the local S:\Data drive ?
    here's my script that I use to copy 11 TB of file server contents:
    robocopy.exe "\\OLDFILESERVER\Data" S:\Data *.* /E /SECFIX /SEC /XO /ZB /COPYALL /MIR /DCOPY:DAT /R:0 /W:0 /NP /NFL /NDL /TEE /LOG:"G:\robocopy.log"
    Any kind of help and assistance would be greatly appreciated.
    Thanks
    /* Server Support Specialist */

    Hi,
    Based on my tests, inherited permissions will not be copied using robocopy.exe.
    That’s because that after we copy or move an objects to another volume, the object inherits the permissions of its new parent folder.
    My suggestion for you is to disable the inheritance on corresponding subfolders, and Convert inherited permissions into explicit permissions on this object. After that, those permissions can be copied.
    Here are some references below for you:
    Robocopy not copying NTFS permissions
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/b36748cd-14d1-47a5-9fb6-878ca93ad6fc/robocopy-not-copying-ntfs-permissions
    How permissions are handled when you copy and move files and folders
    http://support.microsoft.com/kb/310316
    Powershell ACL commands? NTFS Permissions - Turn inherited permissions into explicit permissions and remove inheritance
    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/884e2837-ec1d-4937-83a5-722cd00d7d16/powershell-acl-commands-ntfs-permissions-turn-inherited-permissions-into-explicit-permissions-and?forum=ITCG
    Best Regards,
    Amy

  • Class inhertis from JButton, but button is not visible

    Hi!
    I'm having a class that inherits JButton. The idea was to give the button additional parameters, so it inherits from JButton to have all the attributes from JButton... But the problem is, that the Buttons are only visible when I touch them with the mouse. When I move the window they are invisible again...
    Does anybody know why? Thanks for your help!
    P.S Sorry for my bad english....

    Okay, thanks for that hint!
    Here is the class for the gui:
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    public class Temp extends JFrame{
         private static final long serialVersionUID = 5945597724189252185L;
         private JMenuItem closeItem = null;
         private JMenuItem newItem = null;
         private JPanel mainPanel = null;
         private JLabel startImage = null;
         private MineFieldButton[][] mines = null;
         public Temp(){
              this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              addMenu();
              this.add(getMainPanel());
              this.pack();
         private JPanel getMainPanel(){
              if (mainPanel == null){
                   mainPanel = new JPanel();
                   if (mines == null)
                        mainPanel.add(getStartImage());
                   else{
                        mainPanel.setLayout(new GridBagLayout());
                        GridBagConstraints c = new GridBagConstraints();
                        c.fill = GridBagConstraints.HORIZONTAL;
                        c.ipady = 20;
                        c.ipadx = 20;
                        for (int x=0;x<mines.length;x++){
                             for (int y=0;y<mines[x].length;y++){
                                  c.gridx = x;
                                  c.gridy = y;
                                  mainPanel.add(mines[x][y],c);
              return mainPanel;
         private JLabel getStartImage(){
              if(startImage == null){
                   startImage = new JLabel();
              return startImage;
         private void addMenu(){
              JMenuBar menuBar = new JMenuBar();
              JMenu menu = new JMenu("File");
              menu.add(getNewItem());
              menu.add(getCloseItem());
              menuBar.add(menu);
              this.setJMenuBar(menuBar);
         private JMenuItem getNewItem(){
              if (newItem == null){
                   newItem = new JMenuItem("New");
                   newItem.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent e) {
                             createMines();
              return newItem;
         private JMenuItem getCloseItem(){
              if (closeItem == null){
                   closeItem = new JMenuItem("Close");
                   closeItem.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent e) {
                             System.exit(0);
              return closeItem;
         public void showGUI(){
              this.setVisible(true);
         private void createMines(){
              initMinesGUI();
              this.remove(getMainPanel());
              mainPanel = null;
              this.add(getMainPanel());
              this.pack();
         private void initMinesGUI(){
              mines  = new MineFieldButton[10][10];
              for (int x=0;x<mines.length;x++){
                   for (int y=0;y<mines[x].length;y++){
                        mines[x][y] = new MineFieldButton();
                        mines[x][y].setBorder(BorderFactory.createRaisedBevelBorder());
                        mines[x][y].setX(x);
                        mines[x][y].setY(y);
                        mines[x][y].setNumber(x*y);
    }And here for the class that inherits JButton "MineFieldButton":
    import javax.swing.JButton;
    public class MineFieldButton extends JButton{
         private static final long serialVersionUID = -1020769129018597011L;
         private int number = 0;
         private int x;
         private int y;
         public int getNumber() {
              return number;
         public void setNumber(int number) {
              this.number = number;
         public int getX() {
              return x;
         public void setX(int x) {
              this.x = x;
         public int getY() {
              return y;
         public void setY(int y) {
              this.y = y;
    }I hope that you can find my error.... And that this is a SSCCE :-)
    Thanks!

  • Disappearing Images on JButtons using JDK 1.4.0

    Here is the Java Swing Button example from java.sun.com:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.AbstractButton;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.ImageIcon;
    public class ButtonDemo extends JPanel
    implements ActionListener {
    protected JButton b1, b2, b3;
    public ButtonDemo() {
    ImageIcon leftButtonIcon = new ImageIcon("images/right.gif");
    ImageIcon middleButtonIcon = new ImageIcon("images/middle.gif");
    ImageIcon rightButtonIcon = new ImageIcon("images/left.gif");
    b1 = new JButton("Disable middle button", leftButtonIcon);
    b1.setVerticalTextPosition(AbstractButton.CENTER);
    b1.setHorizontalTextPosition(AbstractButton.LEFT);
    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, 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.");
    //Add Components to this container, using the default FlowLayout.
    add(b1);
    add(b2);
    add(b3);
    public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals("disable")) {
    b2.setEnabled(false);
    b1.setEnabled(false);
    b3.setEnabled(true);
    } else {
    b2.setEnabled(true);
    b1.setEnabled(true);
    b3.setEnabled(false);
    public static void main(String[] args) {
    JFrame frame = new JFrame("ButtonDemo");
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    frame.getContentPane().add(new ButtonDemo(), BorderLayout.CENTER);
    frame.pack();
    frame.setVisible(true);
    Do the following:
    1. Compile and run this example using JDK 1.4.0.
    2. While the frame is up hit the Control + Alt + Delete key sequence.
    3. Now hit the Escape Key.
    4. You will notice that atleast one of the buttons on the Java Swing Example will not have the image painted.
    Now if you force a repaint then the image(s) gets painted correctly.
    Any ideas?

    i've got exactely the same problem in a gui application running on windows nt 4, service pack 6. the problem of the disappearing icons occurs also after returning from the screen lock.
    if you got a solution in the mean time please let me know, thanks a lot
    matthiaszimmermann at yahoo.com

  • Edit method problem???

    Hi,forgive for all the code but i've asked this question before and people asked for more code.The problem is i get an error in publicationmain saying "undefined varible newpublication" so how do i fix this?and is my edit method goin to work?using the get and set method?can u show me how do do this please?feel free to make any other changes.thanxs a reply would be most heplful
    public class publication
    public int PublicationID;
    public String publicationname;
    public String publisher;
    public String PricePerIssue;
    public String pubstatus;
    public String publicationtype;
    public publication(int NewPublicationID, String Newpublicationname, String Newpublisher, String NewPricePerIssue, String Newpubstatus, String Newpublicationtype)
    PublicationID = NewPublicationID;
    publicationname = Newpublicationname;
    publisher = Newpublisher;
    PricePerIssue = NewPricePerIssue;
    pubstatus = Newpubstatus;
    publicationtype = Newpublicationtype;
    public String toString ()
    String pubreport = "---------------------------Publication-Information-----------------------------";
    pubreport += "Publication ID:" PublicationID"/n";
    pubreport += " Publication Title:" publicationname"/n";
    pubreport += " publisher: " publisher"/n";
    pubreport += " price Per Issue: " PricePerIssue"/n";
    pubreport += " publication Status: " pubstatus"/n";
    pubreport += " publication Type: " publicationtype"/n";
    return pubreport;
    public void SetPublicationID(int PubID)
    PublicationID = PubID;
    public int GetPublicationID()
    return PublicationID;
    public void Setpublicationname(String pubname)
    publicationname = pubname;
    public String Getpublicationname()
    return publicationname;
    public void Setpublisher(String Pub)
    publisher = Pub;
    public String Getpublisher()
    return publisher;
    public void SetPricePerIssue(String PPI)
    PricePerIssue = PPI;
    public String GetPricePerIssue()
    return PricePerIssue;
    public void Setpubstatus(String Status)
    pubstatus = Status;
    public String Getpubstatus()
    return pubstatus;
    public void Setpublicationtype(String Pubtype)
    publicationtype = Pubtype;
    public String Getpublicationtype()
    return publicationtype;
    import java.util.*;
    import publication;
    public class PublicationContainer
    LinkedList PubList;
    public PublicationContainer()
    PubList = new LinkedList();
    public int add (publication newpublication)
    PubList.addLast(newpublication);
    return PubList.size();
    private class PubNode
    public publication pubrecord;
    public PubNode next;
    public PubNode (publication thepublicationrecord)
    publication p = thepublicationrecord;
    next = null;
    public String toString()
    return PubList.toString();
    public void remove(int PubID)
    PubList.remove(PubID);
    public publication get(int PubID)
    return (publication)PubList.get(PubID);
    public void set(int PubID,publication newpublication)
    PubList.set(PubID, newpublication);
    import cs1.Keyboard;
    import publication;
    import java.util.*;
    public class publicationmain
    public static void main(String args[])
    PublicationContainer pubdatabase = new PublicationContainer();
    int userchoice;
    boolean flag = false;
    while (flag == false)
    System.out.println("------------------------------------Publications--------------------------------");
    System.out.println();
    System.out.println("please Make a Selection");
    System.out.println();
    System.out.println("1 to add publication");
    System.out.println("2 to delete publication");
    System.out.println("0 to quit");
    System.out.println("3 to View all publications");
    System.out.println("4 to Edit a publication");
    System.out.println("5 to select view of publication");
    System.out.println("6 to produce daily summary");
    System.out.println();
    userchoice = Keyboard.readInt();
    switch (userchoice)     
    case 1:
    String PubName;
    String PricePerIssue;
    String Publisher;
    String Pubstatus;
    String Pubtype;
    int PubID;
    System.out.println ("Enter Publication ID:");
    PubID = Keyboard.readInt();
    System.out.println("Enter Publication Name:");
    PubName = Keyboard.readString();
    System.out.println("Enter Publisher Name");
    Publisher = Keyboard.readString();
    System.out.println("Enter Price per Issue:");
    PricePerIssue = Keyboard.readString();
    System.out.println("Enter Publication status");
    Pubstatus = Keyboard.readString();
    System.out.println("Enter Publication type:");
    Pubtype = Keyboard.readString();
    pubdatabase.add (new publication(PubID, PubName, Publisher, PricePerIssue, Pubstatus, Pubtype));
    break;
    case 0:
    flag = true;
    case 2:
    System.out.println ("Enter Publication ID:");
    PubID = Keyboard.readInt();
    pubdatabase.remove (PubID);
    System.out.println ("publication: "+(PubID)+" removed");
    System.out.println();
    break;
    case 3:
    System.out.println (pubdatabase);
    break;
    case 4:
    System.out.println ("Enter Publication to be edited by Publication ID: ");
    PubID = Keyboard.readInt();
    pubdatabase.get(PubID);
    pubdatabase.set(PubID, newpublication);
    default:
    System.out.println("Incorrect Entry");
    }

    Whoops! Anyone spot the mistake?
    I (blush) forgot to re-instate the serial key for the publications after reading them in from disk.
    Works now ;)
    import javax.swing.JComponent;
    import javax.swing.JList;
    import javax.swing.DefaultListModel;
    import javax.swing.JPanel;
    import javax.swing.JOptionPane;
    import javax.swing.JButton;
    import javax.swing.JScrollPane;
    import javax.swing.JLabel;
    import javax.swing.JComboBox;
    import javax.swing.JTextField;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.Dimension;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.Serializable;
    class Publication
         implements Serializable
         private static final String sFileName= "Publications.ser";
         public static final byte UNKNOWN=     0;
         public static final byte HARDBACK=    1;
         public static final byte PAPERBACK=   2;
         public static final byte AUDIO=       3;
         public static final byte BRAIL=       4;
         public static final byte LARGE_PRINT= 5;
         public static final byte INSTOCK=      1;
         public static final byte BACK_ORDER=   2;
         public static final byte OUT_OF_PRINT= 3;
         private static final String[] sTypeNames=
              { "Unknown", "Hardback", "Paperback", "Audio", "Brail", "Large Print" };
         private static final String[] sStatusNames=
              { "Unknown", "In Stock", "Back Order", "Out of Print" };
         private int mId;
         private String mTitle;
         private String mAuthor;
         private String mPublisher;
         private float mPrice;
         private byte mStatus;
         private byte mType;
         private static Object sIdLock= new Object();
         static int sId;
         public Publication(
              String title, String author, String publisher,
              float price, byte status, byte type)
              setTitle(title);
              setPublisher(publisher);
              setAuthor(author);
              setPrice(price);
              setStatus(status);
              setType(type);
              synchronized (sIdLock) {
                   mId= ++sId;
         public int getId() { return mId; }
         public void setTitle(String title) { mTitle= title; }
         public String getTitle() { return mTitle; }
         public void setAuthor(String author) { mAuthor= author; }
         public String getAuthor() { return mAuthor; }
         public void setPublisher(String publisher) { mPublisher= publisher; }
         public String getPublisher() { return mPublisher; }
         public void setPrice(float price) { mPrice= price; }
         public float getPrice() { return mPrice; }
         public void setStatus(byte status)
              if (status >= INSTOCK && status <= OUT_OF_PRINT)
                   mStatus= status;
              else
                   mStatus= UNKNOWN;
         public byte getStatus() { return mStatus; }
         public String getStatusName() { return sStatusNames[mStatus]; }
         public void setType(byte type)
              if (type >= HARDBACK && type <= LARGE_PRINT)
                   mType= type;
              else
                   mType= UNKNOWN;
         public byte getType() { return mType; }
         public String getTypeName() { return sTypeNames[mType]; }
         public String toString ()
              return
                   " id= " +getId() +
                   ", title= " +getTitle() +
                   ", author= " +getAuthor() +
                   ", publisher= " +getPublisher() +
                   ", price= " +getPrice() +
                   ", status= " +getStatus() +
                   " (" +getStatusName() +")" +
                   ", type= " +getType() +
                   " (" +getTypeName() +")";
         private static void addPublication(DefaultListModel listModel) {
              editPublication(listModel, null);
         private static void editPublication(
              DefaultListModel listModel, Publication publication)
              JPanel panel= new JPanel(new BorderLayout());
              JPanel titlePanel= new JPanel(new GridLayout(0,1));
              JPanel fieldPanel= new JPanel(new GridLayout(0,1));
              JTextField fTitle= new JTextField(20);
              JTextField fAuthor= new JTextField();
              JTextField fPublisher= new JTextField();
              JTextField fPrice= new JTextField();
              JComboBox cbStatus= new JComboBox(sStatusNames);
              JComboBox cbType= new JComboBox(sTypeNames);
              fieldPanel.add(fTitle);
              fieldPanel.add(fAuthor);
              fieldPanel.add(fPublisher);
              fieldPanel.add(fPrice);
              fieldPanel.add(cbStatus);
              fieldPanel.add(cbType);
              titlePanel.add(new JLabel("Title:"));
              titlePanel.add(new JLabel("Author:"));
              titlePanel.add(new JLabel("Publisher: "));
              titlePanel.add(new JLabel("Price:"));
              titlePanel.add(new JLabel("Status:"));
              titlePanel.add(new JLabel("Type:"));
              panel.add(titlePanel, BorderLayout.WEST);
              panel.add(fieldPanel, BorderLayout.EAST);
              if (publication != null) {
                   fTitle.setText(publication.getTitle());
                   fTitle.setEditable(false);
                   fAuthor.setText(publication.getAuthor());
                   fPublisher.setText(publication.getPublisher());
                   fPrice.setText("" +publication.getPrice());
                   cbStatus.setSelectedIndex((int) publication.getStatus());
                   cbType.setSelectedIndex((int) publication.getType());
              int option= JOptionPane.showOptionDialog(
                   null, panel, "New Publication",
                   JOptionPane.OK_CANCEL_OPTION,
                   JOptionPane.PLAIN_MESSAGE,
                   null, null, null
              if (option != JOptionPane.OK_OPTION)
                   return;
              String title=
                   fTitle.getText().length() < 1 ? "Unknown" : fTitle.getText();
              String author=
                   fAuthor.getText().length() < 1 ? "Unknown" : fAuthor.getText();
              String publisher=
                   fPublisher.getText().length() < 1 ? "Unknown" : fPublisher.getText();
              float price= 0.0f;
              try { price= Float.parseFloat(fPrice.getText()); }
              catch (NumberFormatException nfe) { }
              byte status= (byte) cbStatus.getSelectedIndex();
              byte type= (byte) cbType.getSelectedIndex();
              if (publication != null) {
                   publication.setAuthor(author);
                   publication.setPublisher(publisher);
                   publication.setPrice(price);
                   publication.setStatus(status);
                   publication.setType(type);
              else {
                   listModel.addElement(
                        new Publication(title, author, publisher, price, status, type));
         private static void deletePublications(JList list, DefaultListModel listModel)
              if (list.getSelectedIndex() >= 0) {
                   Object[] values= list.getSelectedValues();
                   for (int i= 0; i< values.length; i++)
                        listModel.removeElement(values);
         private static DefaultListModel getListModel()
              DefaultListModel listModel;
              try {
                   ObjectInputStream is=
                        new ObjectInputStream(new FileInputStream(sFileName));
                   listModel= (DefaultListModel) is.readObject();
                   is.close();
                   if (listModel.getSize() > 0) {
                        Publication.sId=
                             ((Publication)
                                  listModel.get(listModel.getSize() -1)).getId();
              catch (Exception e) {
                   JOptionPane.showMessageDialog(
                        null, "Could not find saved Publications, creating new list.",
                        "Error", JOptionPane.ERROR_MESSAGE);
                   listModel= new DefaultListModel();
                   // add a known book to the list (I'm pretty sure this one exists ;)
                   listModel.addElement(
                        new Publication("The Bible", "Various", "God", 12.95f,
                             Publication.INSTOCK, Publication.HARDBACK));
              // add a shutdown hook to save the list model to disk when we exit
              final DefaultListModel model= listModel;
              Runtime.getRuntime().addShutdownHook(new Thread() {
                   public void run() {
                        saveListModel(model);
              return listModel;
         private static void saveListModel(DefaultListModel listModel)
              try {
                   ObjectOutputStream os=
                        new ObjectOutputStream(new FileOutputStream(sFileName));
                   os.writeObject(listModel);
                   os.close();
              catch (IOException ioe) {
                   System.err.println("Failed to save Publications!");
                   ioe.printStackTrace();
         public static void main(String args[])
              // store all the publications in a list model which drives the JList
              // the user will see - we save it on exit, so see if there's one on disk.
              final DefaultListModel listModel= getListModel();
              final JList list= new JList(listModel);
              // two panels, the main one for the dialog and one for buttons
              JPanel panel= new JPanel(new BorderLayout());
              JPanel btnPanel= new JPanel(new GridLayout(1,0));
              // an add button, when pressed brings up a dialog where the user can
              // enter details of a new publication
              JButton btnAdd= new JButton("Add");
              btnAdd.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        addPublication(listModel);
              btnPanel.add(btnAdd);
              // a delete button, when pressed it will delete all the selected list
              // items (if any) and then disable itself
              final JButton btnDelete= new JButton("Delete");
              btnDelete.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        deletePublications(list, listModel);
              btnDelete.setEnabled(false);
              btnPanel.add(btnDelete);
              // hook into the list selection model so we can de-activate the delete
              // button if no list items are selected.
              list.getSelectionModel().addListSelectionListener(
                   new ListSelectionListener() {
                        public void valueChanged(ListSelectionEvent e) {
                             if (list.getSelectedIndices().length > 0)
                                  btnDelete.setEnabled(true);
                             else
                                  btnDelete.setEnabled(false);
              // Watch out for double clicks in the list and edit the document
              // selected
              list.addMouseListener(new MouseListener() {
                   public void mouseClicked(MouseEvent e) {
                        if (e.getClickCount() == 2) {
                             editPublication(
                                  listModel, (Publication) list.getSelectedValue());
                   public void mousePressed(MouseEvent e) { }
                   public void mouseReleased(MouseEvent e) { }
                   public void mouseEntered(MouseEvent e) { }
                   public void mouseExited(MouseEvent e) { }
              // Now keep an eye out for the user hitting return (will edit the selected
              // publication) or delete (will delete it)
              // Note: we have do the ugly "pressed" flag because JOptionPane closes
              // on keyPressed and we end up getting keyReleased. Can't use keyTypes
              // because it does not contain the virtual key code 8(
              list.addKeyListener(new KeyListener() {
                   boolean pressed= false;
                   public void keyTyped(KeyEvent e) { }
                   public void keyPressed(KeyEvent e) {
                        pressed= true;
                   public void keyReleased(KeyEvent e) {
                        if (pressed && e.getKeyCode() == e.VK_ENTER) {
                             editPublication(
                                  listModel, (Publication) list.getSelectedValue());
                        else if (pressed && e.getKeyCode() == e.VK_DELETE)
                             deletePublications(list, listModel);
                        pressed= false;
              // Put the list in a scroll pane so we can see it all. Make it resonably
              // wide so we don't have top scroll horizonatly to see most publications
              JScrollPane listScrollPane= new JScrollPane(list);
              listScrollPane.setPreferredSize(new Dimension(640, 300));
              // layout the list and button panel
              panel.add(listScrollPane, BorderLayout.CENTER);
              panel.add(btnPanel, BorderLayout.SOUTH);
              // ok, ready to rumble, lets show the user what we've got
              JOptionPane.showOptionDialog(
                   null, panel, "Publications",
                   JOptionPane.DEFAULT_OPTION,
                   JOptionPane.PLAIN_MESSAGE,
                   null, new String[0], null
              // leg it
              System.exit(0);

  • Can I grant permission to write in specific attributes using security groups

    Hi
    I Created GPO that write the computer name in the one of the user attribute "comment attribute " when  he logged on
    then i went to OU and grant self delegate permissions to allow the users of that OU to write on "comment attribute
    but this did not work for the users how have been disabled form inheritance
    so instead of grant delegate permissions to the OU
    Can I grant permission to write in specific attribute "comment attribute " using security groups "Domain User "??

    Hi,
    Open Active Directory Users and Computers.
    On the View menu, select Advanced Features.
    Right-click the object for which you want to assign, change, or remove permissions, and then click Properties.
    On the Security tab, click Advanced to view all of the permission entries that exist for the object.
    To assign new permissions on an object or attribute, click Add.
    Type the name of the group, computer, or user that you want to add, and then clickOK.
    In the Permission Entry for ObjectName dialog
    box, on the Object and Properties tabs,
    select or clear the Allow or Deny check
    boxes, as appropriate.
    http://technet.microsoft.com/en-us/library/cc757520(v=ws.10).aspx
    Regards,
    Rafic
    If you found this post helpful, please give it a "Helpful" vote.
    If it answered your question, remember to mark it as an "Answer".
    This posting is provided "AS IS" with no warranties and confers no rights! Always test ANY suggestion in a test environment before implementing!

  • What about MultipleThread?

    This is my source code!
    How thread event has used method paint?
    why method paint() only wake up once?
    SecondCounterLockup.java
    1: import java.awt.*;
    2: import javax.swing.*;
    3: import java.text.*;
    4:
    5: public class SecondCounterLockup extends JComponent {
    6: private boolean keepRunning;
    7: private Font paintFont;
    8: private String timeMsg;
    9: private int arcLen;
    10:
    11: public SecondCounterLockup() {
    12: paintFont = new Font(�SansSerif�, Font.BOLD, 14);
    13: timeMsg = �never started�;
    14: arcLen = 0;
    15: }
    16:
    17: public void runClock() {
    18: System.out.println(�thread running runClock() is � +
    19: Thread.currentThread().getName());
    20:
    21: DecimalFormat fmt = new DecimalFormat(�0.000�);
    22: long normalSleepTime = 100;
    23:
    24: int counter = 0;
    25: keepRunning = true;
    26:
    27: while ( keepRunning ) {
    28: try {
    29: Thread.sleep(normalSleepTime);
    30: } catch ( InterruptedException x ) {
    31: // ignore
    32: }
    33:
    34: counter++;
    35: double counterSecs = counter / 10.0;
    36:
    37: timeMsg = fmt.format(counterSecs);
    38:
    39: arcLen = ( ( ( int ) counterSecs ) % 60 ) * 360 / 60;
    40: repaint();
    41: }
    42: }
    43:
    44: public void stopClock() {
    45: keepRunning = false;
    46: }
    47:
    48: public void paint(Graphics g) {
    49: System.out.println(�thread that invoked paint() is � +
    50: Thread.currentThread().getName());
    51:
    52: g.setColor(Color.black);
    53: g.setFont(paintFont);
    54: g.drawString(timeMsg, 0, 15);
    55:
    56: g.fillOval(0, 20, 100, 100); // black border
    57:
    58: g.setColor(Color.white);
    59: g.fillOval(3, 23, 94, 94); // white for unused portion
    60:
    61: g.setColor(Color.blue); // blue for used portion
    62: g.fillArc(2, 22, 96, 96, 90, -arcLen);
    63: }
    64: }
    v� t&#7853;p tin ch&#7913;a ph��ng th&#7913;c main()
    SecondCounterLockupMain.java�The Class Used to Demonstrate SecondCounterLockup
    1: import java.awt.*;
    2: import java.awt.event.*;
    3: import javax.swing.*;
    4: import javax.swing.border.*;
    5:
    6: public class SecondCounterLockupMain extends JPanel {
    7: private SecondCounterLockup sc;
    8: private JButton startB;
    9: private JButton stopB;
    10:
    11: public SecondCounterLockupMain() {
    12: sc = new SecondCounterLockup();
    13: startB = new JButton(�Start�);
    14: stopB = new JButton(�Stop�);
    15:
    16: stopB.setEnabled(false); // begin with this disabled
    17:
    18: startB.addActionListener(new ActionListener() {
    19: public void actionPerformed(ActionEvent e) {
    20: // disable to stop more �start� requests
    21: startB.setEnabled(false);
    22:
    23: // Run the counter. Watch out, trouble here!
    24: sc.runClock();
    25:
    26: stopB.setEnabled(true);
    27: stopB.requestFocus();
    28: }
    29: });
    30:
    31: stopB.addActionListener(new ActionListener() {
    32: public void actionPerformed(ActionEvent e) {
    33: stopB.setEnabled(false);
    34: sc.stopClock();
    35: startB.setEnabled(true);
    36: startB.requestFocus();
    37: }
    38: });
    39:
    40: JPanel innerButtonP = new JPanel();
    41: innerButtonP.setLayout(new GridLayout(0, 1, 0, 3));
    42: innerButtonP.add(startB);
    43: innerButtonP.add(stopB);
    44:
    45: JPanel buttonP = new JPanel();
    46: buttonP.setLayout(new BorderLayout());
    47: buttonP.add(innerButtonP, BorderLayout.NORTH);
    48:
    49: this.setLayout(new BorderLayout(10, 10));
    50: this.setBorder(new EmptyBorder(20, 20, 20, 20));
    51: this.add(buttonP, BorderLayout.WEST);
    52: this.add(sc, BorderLayout.CENTER);
    53: }
    54:
    55: public static void main(String[] args) {
    56: SecondCounterLockupMain scm = new SecondCounterLockupMain();
    57:
    58: JFrame f = new JFrame(�Second Counter Lockup�);
    59: f.setContentPane(scm);
    60: f.setSize(320, 200);
    61: f.setVisible(true);
    62: f.addWindowListener(new WindowAdapter() {
    63: public void windowClosing(WindowEvent e) {
    64: System.exit(0);
    65: }
    66: });
    67: }
    68: }

    Hey!
    (1)Post a compilable and runnable code!
    (2)Learn Java basics at Sun's tutorial site!!!
    for thread : http://java.sun.com/docs/books/tutorial/essential/threads/index.html
    I hate dirty/ugly code so I somehow/somewhat beautified it:
    /* save as SecondCounterLockupMain.java */
    import java.awt.*;
    import javax.swing.*;
    import java.text.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    class SecondCounterLockup extends JComponent implements Runnable{
      private boolean keepRunning;
      private Font paintFont;
      private String timeMsg;
      private int arcLen;
      public boolean doPause;
      public SecondCounterLockup() {
        paintFont = new Font("SansSerif", Font.BOLD, 14);
        timeMsg = "never started";
        arcLen = 0;
        doPause = false;
      public void run(){
        DecimalFormat fmt = new DecimalFormat("0.000");
        long normalSleepTime = 100;
        int counter = 0;
        keepRunning = true;
        while (keepRunning){
          if (! doPause){
            try{
              Thread.sleep(normalSleepTime);
            }catch ( InterruptedException x ) {
              x.printStackTrace();
            counter++;
            double counterSecs = counter / 10.0;
            timeMsg = fmt.format(counterSecs);
            arcLen = (((int)counterSecs) % 60) * 360 / 60;
            repaint();
      public void stopClock() {
        keepRunning = false;
      public void pause(){
        doPause = ! doPause;
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.black);
        g.setFont(paintFont);
        g.drawString(timeMsg, 0, 15);
        g.fillOval(0, 20, 100, 100); // black border
        g.setColor(Color.white);
        g.fillOval(3, 23, 94, 94); // white for unused portion
        g.setColor(Color.blue); // blue for used portion
        g.fillArc(2, 22, 96, 96, 90, -arcLen);
    public class SecondCounterLockupMain extends JPanel {
      private SecondCounterLockup sc;
      private JButton startB;
      private JButton stopB;
      JButton pauseB;
      Thread t;
      public SecondCounterLockupMain(){
        sc = new SecondCounterLockup();
        startB = new JButton("Start");
        stopB = new JButton("Stop");
        stopB.setEnabled(false); // begin with this disabled
        pauseB = new JButton("Pause");
        pauseB.setEnabled(false); // begin with this disabled
        startB.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // disable to stop more �start� requests
            startB.setEnabled(false);
            pauseB.setEnabled(true);
            t = new Thread(sc);
            t.start();
            stopB.setEnabled(true);
            stopB.requestFocus();
        stopB.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            stopB.setEnabled(false);
            sc.stopClock();
            startB.setEnabled(true);
            pauseB.setEnabled(false);
            startB.requestFocus();
        pauseB.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (sc.doPause){ // goes to unpause
              pauseB.setText("Pause");
              startB.setEnabled(false);
              stopB.setEnabled(true);
            else{ // goes to pause
              pauseB.setText("Rerun");
              startB.setEnabled(false);
              stopB.setEnabled(false);
            sc.pause();
        JPanel innerButtonP = new JPanel();
        innerButtonP.setLayout(new GridLayout(0, 1, 0, 3));
        innerButtonP.add(startB);
        innerButtonP.add(stopB);
        innerButtonP.add(pauseB);
        JPanel buttonP = new JPanel();
        buttonP.setLayout(new BorderLayout());
        buttonP.add(innerButtonP, BorderLayout.NORTH);
        this.setLayout(new BorderLayout(10, 10));
        this.setBorder(new EmptyBorder(20, 20, 20, 20));
        this.add(buttonP, BorderLayout.WEST);
        this.add(sc, BorderLayout.CENTER);
      public static void main(String[] args) {
        SecondCounterLockupMain scm = new SecondCounterLockupMain();
        JFrame f = new JFrame("Second Counter Lockup");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setContentPane(scm);
        f.setSize(320, 200);
        f.setVisible(true);
    }

  • Dreamweaver overriding server file permissions

    We currently use Dreamweaver CS4, and for some reason sometimes when checking out a file, working on it, then checking it back in, it changes the permissions that that file originally had on the server.
    Each folder on our server has a set of permissions tied to logins and the files in each folder inherit their permissions from there. However, sometimes dreamweaver decised to completely change the set of permissions that a file has on the server and disabling the inheritance of permissions entirely on said file. It seems that it changes the ownership of the file from Administrator to Contribute User, but whether this is the cause of the permission changes or a symptom, im not sure.
    The oddest thing, however, is that it is far from consistant. It seems that the files that get affected by this are random and it dosn't always happen to the same file twice.
    Has anyone else experienced this before or know what could possibly be causing this?
    Thanks
    -Nick

    Just bumping this to see if anyone else has had any luck since i first posted. This issue appears to be happening on several people's computers so it's some conflict between dreamweaver and the server that's causing the bug to happen.
    The server we're working on is running Windows Server 2008 with IIS7. Would there be any inherent permissioning conflicts that would explain this issue? If not, is there a way to have dreamweaver not touch permissions at all? Could this be an issue with the checkin/checkout system in dreamweaver?
    Thanks for the help,
    -Nick

  • Issue with folder permissions assigned to a group

    There is probably a simple and obvious answer to this, but I have not been able to find it by searching.
    Here's the situation:
    We are new to Active Directory in my company.  We have a machine joined to a Domain.  On the Domain Controller, we have a security group called Accounting.  On the domain joined machine, I have added the Accounting security group to the machine's
    local Remote Desktop Users group.  This works fine, all user accounts that are part of Accounting can now login with RDC.
    Next, I create a folder, c:\test.  I disable permission inheritance on c:\test, then remove all permissions entries except for CREATOR OWNER and SYSTEM.  I do not change any permissions granted to these two.  Now, I add the Accounting security
    group to this folder, and grant that group Full Control permissions.
    When one of the members of the Accounting security group logs in and attempts to open c:\test with windows Explorer, it states they do not have permission to access the folder, and it requests an Administrator account and password.
    I even went into advanced security settings to the Effective Access tab, entered the user account of one the Accounting security group's members, and effective access states that said user account has full control permissions.
    It seems to me that a member of a security group that is granted Full Control permissions on a folder *should* be able to open said folder without incident.  What am I missing?
    ADDITIONAL INFO: The Accounting security group has a scope of Domain Local, in case that is important.

    Hi,
    Glad to hear that this issue has been solved and thanks for sharing in the forum. Your time and efforts are highly appreciated.
    Best regards,
    Justin Gu

  • Can i change the color of the text of a JButton, when it is disabled?

    Hi,
    I want to keep the black foreground of my JButton even after I disable it. I have tried using:
    .setForeground(Color.black);
    but it remains gray. Is there anyway to do this?
    thanks!

    just a thought...
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Testing extends JFrame
      public Testing()
        setLocation(400,300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel jp = new JPanel(new GridLayout(2,1));
        final JButton btn = new JButton("Enabled");
        btn.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            JOptionPane.showMessageDialog(getContentPane(),"Hello World");}});
        JCheckBox cbx = new JCheckBox("Enable/Disable",true);
        cbx.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            btn.setEnabled(!btn.isEnabled());
            //btn.setText(btn.isEnabled()? "Enabled":"Disabled");}});//toggle these lines
            btn.setText(btn.isEnabled()? "Enabled":"<html><font color=black>Disabled</font></html>");}});
        jp.add(btn);
        jp.add(cbx);
        getContentPane().add(jp);
        pack();
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • +, - button and inherited tick box is in disabled mode for account assignme

    In the attribute tab of org structure (PPOMA_BBP), we are not getting +, - button and inherited tick box is in disabled mode for account assignment category (attribute is KNT).
    We want to enter two values for the account assignment category with inherited tick box (ticked).
    Please suggest me how to get the +, - and inherited tick box (ticked) for the account assignment.
    Regards.

    Hi Imam,
    Unde attributes
    You will find one Application Toolbar...
    Overview, Select Attribute, Check Entries,Insert line,Delete line..
    So under All values you will find AcctAssigCat, Exculded, Default, Inheried
    Select the row and click on Insert Line, now you should be able to insert the new acct Assignment category
    rg
    sam

  • Problem disabling JButton in ActionListener after setText of JLabel

    What i want is when i click View to see the label say "Viewing ..." and in the same time the btnView (View Button) to be disabled.
    I want the same with the other 2 buttons.
    My problem is in ActionListener of the button. It only half works.
    I cannot disable (setEnabled(false)) the button after it is pressed and showing the JLabel.
    The code i cannot run is the 3 buttons setEnabled (2 in comments).
    Any light?
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    class BTester extends JFrame implements ActionListener { 
         JButton btnView, btnBook, btnSearch;
         BTester(){     //Constructor
              JPanel p = new JPanel();
         JButton btnView = new JButton( "View" );
         btnView.setActionCommand( "View" );
         btnView.addActionListener(this);
         JButton btnBook = new JButton( "Book" );
         btnBook.setActionCommand( "Book" );
         btnBook.addActionListener(this);
         JButton btnSearch = new JButton( "Search" );
         btnSearch.setActionCommand( "Search" );
         btnSearch.addActionListener(this);
         p.add(btnView);
         p.add(btnBook);
         p.add(btnSearch);
         getContentPane().add(show, "North"); //put text up
    getContentPane().add(p, "South"); //put panel of buttons down
    setSize(400,200);
    setVisible(true);
    setTitle("INITIAL BUTTON TESTER");
    show.setFont(new Font("Tahoma",Font.BOLD,20));
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     
         //actionPerformed implemented (overrided)
         public void actionPerformed( ActionEvent ae) {
    String actionName = ae.getActionCommand().trim();
    if( actionName.equals( "View" ) ) {
    show.setText("Viewing ...");
         btnView.setEnabled(false); // The line of problem
    //btnBook.setEnabled(true);
    //btnSearch.setEnabled(true);
    else if( actionName.equals( "Book" ) ) {
    show.setText("Booking ...");
    //btnView.setEnabled(true);
    //btnBook.setEnabled(false);
    //btnSearch.setEnabled(true);
    else if( actionName.equals( "Search" ) ) {
    show.setText("Searching ...");
    //btnView.setEnabled(true);
    //btnBook.setEnabled(true);
    //btnSearch.setEnabled(false);
    } //end actionPerformed
         private JLabel show = new JLabel( "Press a button ... " );
    public static void main(String[] args) { 
         new BTester();
    } // End BTester class

    1. Use code formatting when posting code.
    2. You have a Null Pointer Exception since in your constructor you create the JButtons and assign them to a local variable instead of the class member.
    Change this
    JButton btnView = new JButton( "View" );to:
    btnView = new JButton( "View" );

  • How to disable the highlight i get on a JButton when it's helddown\pressed?

    couldn't find it anywhere..is there a way to disable the blueish highlight i get when it's pressed?or is the only option to make a glass pane over it?

    setUI of the JButton and override paintButtonPressed with an empty method:JButton button = new JButton ("Click");
    button.setUI (new MetalButtonUI () {
        protected void paintButtonPressed (Graphics g, AbstractButton b) { }
    });Suitable for Metal L&F only.
    May I ask the reason behind this requirement?
    db

Maybe you are looking for

  • Disk drive thrashing after waking from sleep

    Apple conundrum - iMac goes from sleepy to grumpy.... At times after waking from sleep mode, my disk drive thrashes for up to 3-5 minutes. The thrashing almost always includes an SSBOD. Then it stops and things seem fine.  My iMac is not backing up a

  • LIST aggregate function

    Hello, In SAP Sybase SQL Anywhere have aggregate function List() This function is very useful! Prompt, this function is planned in ASE?

  • FM for updating Partner details in Sales order

    Hi, Pleaes let me know the FM to update partner functions in sales documents. FM is expected to only update partners and shouldnu2019t update pricing or incompletion or anything else. thanks

  • How Transformations or Routines will work for the NLS Archived data in BW on HANA?

    Hi, I have archived data from BW on HANA system into NLS IQ. Now I'm creating a Transformation or Routines, in this case how the archived data will be read without writing any ABAP Code. Thanks & Regards, Ramana SBLSV.

  • Can't write on external SD card after upgradatio​n

    I can't write on my external SD card of my HP slate7 after it was upgraded to KitKat version. It is saying as your Android os is changed you can no longer write on your external SD card. How can I solve this??