Blotching of JButtons

I am not sure if its a bug but this really seems like one. When i add a JPanel to a JFrame and add a JToolbar in vertical orientation with the buttons having the bevel raised border in java 1.5, these wierd blotching occur on the edges of the buttons.
Can anyone help me with this? its on java1.5.0_03
here is the code
* Album.java
* Created on July 22, 2005, 3:15 PM
package Album;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
import javax.swing.JFileChooser;
import javax.swing.UIManager;
* @author ccb3101
public class Album extends javax.swing.JFrame {
/** Creates new form Album */
public Album() {
try
UIManager.setLookAndFeel (new WindowsLookAndFeel());
catch(Exception e){e.printStackTrace ();}
initComponents();
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents()
jPanel1 = new javax.swing.JPanel();
jToolBar1 = new javax.swing.JToolBar();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
File = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenu1 = new javax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new java.awt.BorderLayout());
jToolBar1.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
jToolBar1.setFloatable(false);
jToolBar1.setOrientation(1);
jToolBar1.setVerifyInputWhenFocusTarget(false);
jButton1.setText("jButton1");
jButton1.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
jButton1.setDoubleBuffered(true);
jButton1.setMargin(new java.awt.Insets(2, 2, 2, 2));
jToolBar1.add(jButton1);
jButton2.setText("jButton2");
jButton2.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
jToolBar1.add(jButton2);
jButton3.setText("jButton3");
jButton3.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
jToolBar1.add(jButton3);
jButton4.setText("jButton4");
jButton4.setBorder(new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.RAISED));
jToolBar1.add(jButton4);
jPanel1.add(jToolBar1, java.awt.BorderLayout.EAST);
getContentPane().add(jPanel1, java.awt.BorderLayout.EAST);
fileMenu.setText("File");
fileMenu.addActionListener(new java.awt.event.ActionListener()
public void actionPerformed(java.awt.event.ActionEvent evt)
fileMenuActionPerformed(evt);
jMenuItem1.setText("Item");
jMenuItem1.addActionListener(new java.awt.event.ActionListener()
public void actionPerformed(java.awt.event.ActionEvent evt)
jMenuItem1ActionPerformed(evt);
fileMenu.add(jMenuItem1);
File.add(fileMenu);
jMenu1.setText("Edit");
File.add(jMenu1);
setJMenuBar(File);
pack();
// </editor-fold>
private void fileMenuActionPerformed(java.awt.event.ActionEvent evt) {                                        
// TODO add your handling code here:
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
JFileChooser fileChooser = new JFileChooser();
fileChooser.setVisible(true);
* @param args the command line arguments
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Album().setVisible(true);
// Variables declaration - do not modify
private javax.swing.JMenuBar File;
private javax.swing.JMenu fileMenu;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JPanel jPanel1;
private javax.swing.JToolBar jToolBar1;
// End of variables declaration
}

Oki.
I thought that an array would be good. Easier to control the buttons then.
After I clicked one of the buttons i get a new frame with new buttons and so forth and so on.
If I don't have arrays I have to write almost the same thing for all the buttons...
Do you have a better idea, I'm more than glad to hear!

Similar Messages

  • Blotch on display

    In the lower left hand side of my display there is a redish (when on a white background) blotch, that is see through, but reveals an uneven color quality on my screen, how can I fix this, or should I return my whole laptop?

    I have a similar issue. On the menubar at the top of my 13" Macbook Pro, there's a reddish tint towards the right of the screen and a few pixels that appear slightly "blocky". The tint makes the color of the menu bar inconsistent from left to right.
    I got mine right around Thanksgiving, but it looks like I'll be needing to take a trip to the Apple store...
    What ended up happening with yours?

  • Resized animated gif ImageIcon not working properly with JButton etc.

    The problem is that when I resize an ImageIcon representing an animated gif and place it on a Jbutton, JToggelButton or JLabel, in some cases the image does not show or does not animate. More precicely, depending on the specific image file, the image shows always, most of the time or sometimes. Images which are susceptible to not showing often do not animate when showing. Moving over or clicking with the mouse on the AbstractButton instance while the frame is supposed to updated causes the image to disappear (even when viewing the non-animating image that sometimes appears). No errors are thrown.
    Here some example code: (compiled with Java 6.0 compliance)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test
         public static void main(String[] args)
              new Test();
         static final int  IMAGES        = 3;
         JButton[]           buttons       = new JButton[IMAGES];
         JButton             toggleButton  = new JButton("Toggle scaling");
         boolean            doScale       = true;
         public Test()
              JFrame f = new JFrame();
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel p = new JPanel(new GridLayout(1, IMAGES));
              for (int i = 0; i < IMAGES; i++)
                   p.add(this.buttons[i] = new JButton());
              f.add(p, BorderLayout.CENTER);
              f.add(this.toggleButton, BorderLayout.SOUTH);
              this.toggleButton.addActionListener(new ActionListener() {
                   @Override
                   public void actionPerformed(ActionEvent e)
                        Test.this.refresh();
              f.setSize(600, 300);
              f.setVisible(true);
              this.refresh();
         public void refresh()
              this.doScale = !this.doScale;
              for (int i = 0; i < IMAGES; i++)
                   ImageIcon image = new ImageIcon(i + ".gif");
                   if (this.doScale)
                        image = new ImageIcon(image.getImage().getScaledInstance(180, 180, Image.SCALE_AREA_AVERAGING));
                   image.setImageObserver(this.buttons);
                   this.buttons[i].setIcon(image);
                   this.buttons[i].setSelectedIcon(image);
                   this.buttons[i].setDisabledIcon(image);
                   this.buttons[i].setDisabledSelectedIcon(image);
                   this.buttons[i].setRolloverIcon(image);
                   this.buttons[i].setRolloverSelectedIcon(image);
                   this.buttons[i].setPressedIcon(image);
    Download the gif images here:
    http://djmadz.com/zombie/0.gif
    http://djmadz.com/zombie/1.gif
    http://djmadz.com/zombie/2.gif
    When you press the "Toggle scaling"button it switches between unresized (properly working) and resized instances of three of my gif images. Notice that the left image almost never appears, the middle image always, and the right image most of the time. The right image seems to (almost) never animate. When you click on the left image (when visble) it disappears only when the backend is updating the animation (between those two frames with a long delay)
    Why are the original ImageIcon and the resized ImageIcon behaving differently? Are they differently organized internally?
    Is there any chance my way of resizing might be wrong?

    It does work, however I refuse to use SCALE_REPLICATE for my application because resizing images is butt ugly, whether scaling up or down. Could there be a clue in the rescaling implementations, which I can override?
    Maybe is there a way that I can check if an image is a multi-frame animation and set the scaling algorithm accordingly?
    Message was edited by:
    Zom-B

  • Unable to  trace JButton event

    hello there,
    iam creating a JButton on which iam setting an imageicon .
    instead of the image path to the constructor of jbutton iam passing the
    byte array of that image.
    now the problem is when i click on that button, iam unable to trace in the actionperformed method that this particular button was clicked.
    any help in this regard is mostly appreciated.
    bye

    sorry. a small correction to the above sentence
    iam creating that image through the byte array which is passed to the constructor of the ImageIcon. now this imageicon object is passed to the constructor of the jbutton.

  • Getting the label of a JButton in a for loop

    hi,
    I doing a project for my course at the minute and im in need of a bit of help. I have set up 1-d array of buttons and i have layed them out using a for loop. I have also added an annoymous action listener to each button in the loop. It looks something lke this:
    b = new JButton[43];
    for (int i=1; i<43; i++)
    b[i] = new JButton(" ");
    b.addActionListener(
    new ActionListener()
    public void actionPerformed(ActionEvent e)
              System.out.println("..........");
    }); // addActionListener
    } // for
    I want the "System.out.println( ..." line, to print out the "i" number of the button that was pressed but i cannot figure out how to do it. I cannot put "System.out.println(" "+i);" as it wont recognise i as it is not inside the for loop. Does anyone have any suggestions?
    Thanks!!

    class ButtonExample extends JFrame implements ActionListener{The OP wanted to have anonymous listeners, not a subclassed JFrame
    listening to the buttons. I don't know if the following is the best design,
    since the poster has revealed so little, but here is how to pass the
    loop index to an anonymous class.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ButtonExample {
        private JButton[] buttons = new JButton[24];
        public JPanel createGUI() {
            JPanel gui = new JPanel(new GridLayout(6,  4));
            for(int i=0; i<buttons.length; i++) {
                final int ii = i; //!! !
                buttons[i] = new JButton("button #" + i);
                buttons.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent evt) {
    System.out.println("number " + ii);
    gui.add(buttons[i]);
    return gui;
    public static void main(String[] args) {
    ButtonExample app = new ButtonExample();
    JPanel gui = app.createGUI();
    JFrame f = new JFrame("ButtonExample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(gui);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);

  • Blotch on screen, cause?

    Please see the link below for a picture.
    Can anyone able to help me identify what the problem is or what's caused the blotch? My phone hasn't been submerged in water or anything so I can rule out water damage. The blotch appears to be underneath the screen.
    https://twitter.com/tommmrp/status/518818327247216640

    www.ipodresq.com
    www.ipodmods.com

  • Blotch on a macbook pro 13 screen

    i have a macbook pro 13 inch the non-retina version and it has a blotch a little towards the left from the center
    i still have 1 year limited warranty
    will it be covered at apple retail store under the warranty?????

    If the computer came with that defect and you didn't do anything, take the Mac to an Apple Store and it will be fixed for free

  • Blotch on the printing drum of Select 360

    I recently installed a new toner cartridge in my Select 360 Laserwriter. An ink blotch is showing up, mid-page, every inch and a half. I have gone ahead and printed out pages, hoping the blotch would come off on the print pages, but it persists after 100 pages.
    Cartridge instructions warn against opening the flap or handling the drum. Any suggestions?
    Thanks!

    Jim,
    When you replace a toner cartridge, you also need to vaccum out the printer. Some toner has fallen into the printer rollers and is being picked up by the paper.
    The inch and a half measurement tells you which roller it is because they use rollers of a different circumference in different locations of the printer so a technician can tell which roller needs to be cleaned.
    I am not at the computer that has those measurements but I can look them up. You can also check "fixyourowncomputer.com" for additional cleaning help.
    I would start with a vaccum and a soft felt pad. Good luck.
    Jim

  • Blotch on my 13 inch macbook pro screen non retina

    i have a black blotch on my 13 inch non retina macbook pro mid 2012. the warranty expires in august. Since I requested for this mac from my relatives, i dont have a reciept but the waranty shows on apple's site. i paid for the mac and i live in a country where there is no apple authorized dealer. the closest i can get to is malaysia. will the warranty be covered there. if yes  then will they repair it or will there be an option for refund???
    i really need help with this

    Apple warranty coverage is international.
    The AppleCare Protection Plans for Mac and iPod provide global repair coverage. If you take your Apple hardware with you when you travel and happen to need repair service, you can either go to an Apple Retail Store or contact Apple for information on how to obtain service. Service will be limited to the options available in the country where service is requested. Service options, parts availability, and response time vary according to country. Please see the AppleCare Protection Plan Terms and Conditions for complete details.
    http://www.apple.com/support/products/faqs.html

  • Display Problem on MacBook Pro 13-In:  red blotch when screen is dark/black

    I've been having a really weird problem:  a red blotch near the center of my screen, visible if the screen is black, or dark background in video playback.  It's about an inch off center (right) and it look like a "T" made by a paint brush stroke.  When it first appeared (in the same spot to the left of center), Apple replaced the display (in the last year of Apple Care), and it disappeared.  It reappeared 4 weeks later as clear lines (in the same spot).  They replaced the display again, and it disappeared once again.  It happened a third time 4 months after that, and they replaced the logic board as well as the display; again, "fixed."  Here's the weirdest part:  because, after all this, the computer would not charge, they threw up their hands and gave me a brand new MacBook Pro. That was a month ago, and last night, there was the red blotch again (except now, again, just to the right of center).
    I can't find anything like this (online) happening to anyone else, and so far Apple hasn't determined what they think the problem is.  I sort of feel now the problem must lie with me.  But what could I be doing?  I haven't dropped it; I'm just using it for email and reading online.
    Anyone have any idea what this might be?  Thank you very much in advance for any suggestions.

    I can only do wild guesses at this popint, only thing I can think of on your end is possible AC power problems, but I've not been impressed with Apple's quality since the 68K or Beige days.
    THe iMac7,1 I'm on now needed repair 3 times & still scares me with it's PSU temps.

  • Large blotch appears on display

    I have an iBook G4 which Apple replaced for my G3. The G3 was part of the extended logic board program; they tried to repair it three times but were unsuccessful. I've had the G4 for less than 12 months. I've never had a problem with it until today. When I turned it on there was a very large blotch of black and white in a free-form design covering 3/4 of the screen. I tried to restart, then shut-down and restart but nothing got rid of the blotch. I can see the outline of the blotch when the machine is off. Is this another logic board problem? I wrote to Apple and am waiting for their reply.

    Not correct. You received a refurbished G4 as a
    replacement for your G3.
    Hmmm... Interesting concept. According to the
    Customer Relations person who sent it to me
    originally, it was new. According to the Customer
    Service guy my husband talked to today, the only way
    to get a refurbished laptop is to actually purchase
    one (and he said he couldn't look it up by the S/N
    because once it was registered to us, all he sees is
    our info.)
    Then this is an even better reason to buy from Apple. In the electronics industry, it is standard practice to use refurbished components when repairing/replacing defective one. That is what is written on the fine print of every RMA I have ever seen. That doesn't mean they can't or won't give you new parts for a repair or replacement. It just means if they do, they are going above and beyond anyone else. And, for what it's worth, I would take a refurbished Apple over a new PC any day. I am a proud owner of an Apple-refurbished iPod - works like a charm.
    This whole discussion has re-lit the fire in my
    husband and he is pushing the issue now (it is still
    under warranty until Oct.)
    Squeaky wheel gets the grease. I just think that if you had one of the lemon G3 that had to be repaired 6 times and finally replaced, and the replacement screen cracked, they should give you a new machine. You've suffered enough.
    We would have purchased what instead?? A PC? And
    perhaps run Windows on it?? (excuse me while I pick
    myself up off the floor from laughing.)
    That's nice to hear to a change. Usually it is something like - "I bought this first generation MacBook and it has a funny noise and runs hot. I'm filing a class-action lawsuit!!!"

  • How to display a JPanel of JButtons on ImagePanel?

    Hi
    From the Swing Hacks examples, I can display a JButton on an ImagePanel no problem. But when I put this JButton in JPanel, then add the JPanel to the ImagePanel, the JPanel with the JButton is not displayed.
    Can someone please explain why this is?
    Here is the ImagePanel code:
    import java.awt.*;
    import javax.swing.*;
    public class ImagePanel extends JPanel {
        private Image img;
        public ImagePanel(String img) {
            this(new ImageIcon(img).getImage());
        public ImagePanel(Image img) {
            this.img = img;
            Dimension size = new Dimension(img.getWidth(null),img.getHeight(null));
            setPreferredSize(size);
            setMinimumSize(size);
            setMaximumSize(size);
            setSize(size);
            setLayout(null);
        public void paintComponent(Graphics g) {
            g.drawImage(img,0,0,null);
    }And here is the code to add a JButton to a JPanel, then add the JPanel to the ImagePanel:
    import javax.swing.*;
    import java.awt.event.*;
    public class ImageTest {
        public static void main(String[] args) {
           ImagePanel panel = new ImagePanel(new ImageIcon("images/background.png").getImage());
           JPanel buttonPanel = new JPanel()       
            JButton button = new JButton("Button");
            buttonPanel.add(button);
           JFrame frame = new JFrame("Hack #XX: Image Components");
            frame.getContentPane().add(button);    // WORKS!
            //frame.getContentPane().add(buttonPanel);   // NO BUTTON IS DISPLAYED???
           frame.pack();
            frame.setVisible(true);
    }Thanks

    setLayout(null);When you use a null layout then you are responsible for setting the size and location of any component added to the panel. The default location is (0,0) so thats ok, but the default size of the button panel is also (0,0) which is why nothing get painted.
    Don't use a null layout. Let the layout manager layout any component added to it.
    Also, I would override the getPreferredSize() method of your ImagePanel to return the size of the image, instead of setting the preferred size in the constructor.

  • How do i use jbutton for mutiple frames(2frames)???

    im an creating a movie database program and i have a problem with the jButtons on my second frame i dont know how to make them work when clicked on. i managed to make the jButtons work on my first frame but not on the second....
    here is that code so far----
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JTextField;
    * real2.java
    * Created on December 7, 2007, 9:00 AM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    * @author J
    public class real2 extends JPanel  implements ActionListener{
        private JButton addnew;
        private JButton help;
        private JButton exit;
        private JFrame frame1;
        private JButton save;
        private JButton cancel;
        private JButton save2;
        private JLabel moviename;
        private JTextField moviename2;
        private JLabel director;
        private JTextField director2;
        private JLabel year;
        private JTextField year2;
        private JLabel genre;
        private JTextField genre2;
        private JLabel plot;
        private JTextField plot2;
        private JLabel rating;
        private JTextField rating2;
        /** Creates a new instance of real2 */
        public real2() {
            super(new GridBagLayout());
            //Create the Buttons.
            addnew = new JButton("Add New");
            addnew.addActionListener(this);
            addnew.setMnemonic(KeyEvent.VK_E);
            addnew.setActionCommand("Add New");
            help = new JButton("Help");
            help.addActionListener(this);
            help.setActionCommand("Help");
            exit = new JButton("Exit");
            exit.addActionListener(this);
            exit.setActionCommand("Exit");
           String[] columnNames = {"First Name",
                                    "Last Name",
                                    "Sport",
                                    "# of Years",
                                    "Vegetarian"};
            Object[][] data = {
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new Integer(10), new Boolean(false)}
            final JTable table = new JTable(data, columnNames);
            table.setPreferredScrollableViewportSize(new Dimension(600, 100));
            table.setFillsViewportHeight(true);
            //Create the scroll pane and add the table to it.
            JScrollPane scrollPane = new JScrollPane(table);
            //Add the scroll pane to this panel.
            add(scrollPane);
            GridBagConstraints c = new GridBagConstraints();
            c.weightx = 1;
            c.gridx = 0;
            c.gridy = 1;
            add(addnew, c);
            c.gridx = 0;
            c.gridy = 2;
            add(help, c);
            c.gridx = 0;
            c.gridy = 3;
            add(exit, c);
        public static void addComponentsToPane(Container pane){
            pane.setLayout(null);
            //creating the components for the new frame
            JButton save = new JButton("Save");
            JButton save2 = new JButton("Save and add another");
            JButton cancel = new JButton("Cancel");
            JLabel moviename= new JLabel("Movie Name");
            JTextField moviename2 = new JTextField(8);
            JLabel director = new JLabel("Director");
            JTextField director2 = new JTextField(8);
            JLabel genre = new JLabel("Genre");
            JTextField genre2 = new JTextField(8);
            JLabel year = new JLabel("year");
            JTextField year2 = new JTextField(8);
            JLabel plot = new JLabel("Plot");
            JTextField plot2 = new JTextField(8);
            JLabel rating = new JLabel("Rating(of 10)");
            JTextField rating2 = new JTextField(8);
            //adding components to new frame
            pane.add(save);
            pane.add(save2);
            pane.add(cancel);
            pane.add(moviename);
            pane.add(moviename2);
            pane.add(director);
            pane.add(director2);
            pane.add(genre);
            pane.add(genre2);
            pane.add(year);
            pane.add(year2);
            pane.add(plot);
            pane.add(plot2);
            pane.add(rating);
            pane.add(rating2);
            //setting positions of components for new frame
                Insets insets = pane.getInsets();
                Dimension size = save.getPreferredSize();
                save.setBounds(100 , 50 ,
                         size.width, size.height);
                 size = save2.getPreferredSize();
                save2.setBounds(200 , 50 ,
                         size.width, size.height);
                 size = cancel.getPreferredSize();
                cancel.setBounds(400 , 50 ,
                         size.width, size.height);
                 size = moviename.getPreferredSize();
                moviename.setBounds(100 , 100 ,
                         size.width, size.height);
                size = moviename2.getPreferredSize();
                moviename2.setBounds(200 , 100 ,
                         size.width, size.height);
                 size = director.getPreferredSize();
                director.setBounds(100, 150 ,
                         size.width, size.height);
                 size = director2.getPreferredSize();
                director2.setBounds(200 , 150 ,
                         size.width, size.height);
                size = genre.getPreferredSize();
                genre.setBounds(100 , 200 ,
                         size.width, size.height);
                 size = genre2.getPreferredSize();
                genre2.setBounds(200 , 200 ,
                         size.width, size.height);
                 size = year.getPreferredSize();
                year.setBounds(100 , 250 ,
                         size.width, size.height);
                size = year2.getPreferredSize();
                year2.setBounds(200 , 250 ,
                         size.width, size.height);
                 size = plot.getPreferredSize();
                plot.setBounds(100 , 300 ,
                         size.width, size.height);
                 size = plot2.getPreferredSize();
                plot2.setBounds(200 , 300 ,
                         size.width, size.height);
                size = rating.getPreferredSize();
                rating.setBounds(100 , 350 ,
                         size.width, size.height);
                 size = rating2.getPreferredSize();
                rating2.setBounds(200 , 350 ,
                         size.width, size.height);
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            frame.add(new real2());
            //Display the window.
            frame.setSize(600, 360);
            frame.setVisible(true);
            frame.pack();
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
        public void actionPerformed(ActionEvent e) {
            if ("Add New".equals(e.getActionCommand())){
               frame1 = new JFrame("add");
               frame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
               addComponentsToPane(frame1.getContentPane());
               frame1.setSize(600, 500);
               frame1.setVisible(true);
                //disableing first frame etc:-
                if (frame1.isShowing()){
                addnew.setEnabled(false);
                help.setEnabled(false);
                exit.setEnabled(true);
                frame1.setVisible(true);
               }else{
                addnew.setEnabled(true);
                help.setEnabled(true);
                exit.setEnabled(true);           
            if ("Exit".equals(e.getActionCommand())){
                System.exit(0);
            if ("Save".equals(e.getActionCommand())){
                // whatever i ask it to do it wont for example---
                help.setEnabled(true);
            if ("Save" == e.getSource()) {
                //i tried this way too but it dint work here either
                help.setEnabled(true);
    }so if someone could help me by either telling me what to type or by replacing what iv done wrong that would be great thanks...

    (1)Java class name should begin with a capital letter. See: http://java.sun.com/docs/codeconv/
            JButton save = new JButton("Save");
            JButton save2 = new JButton("Save and add another");
            // ... etc. ...(2)Don't redeclare class members in a method as its local variable. Your class members become eternally null, a hellish null.
    how to make them work when clicked on(3)Add action listener to them.

  • Getting values from JLabel[] with JButton[] help!

    Hello everyone!
    My problem is:
    I have created JPanel, i have an array of JButtons and array of JLabels, they are all placed on JPanel depending from record count in *.mdb table - JLabels have its own value selected from Access table.mdb! I need- each time i press some button,say 3rd button i get value showing from 3rd JLabel in some elsewere created textfield, if i have some 60 records and 60 buttons and 60 labels its very annoying to add for each button actionlistener and for each button ask for example jButton[1].addActionListener() ...{ jLabel[1].getText()......} and so on!
    Any suggestion will be appreciated! Thank you!

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class Testing
      public void buildGUI()
        final int ROWS = 10;
        JPanel[] rows = new JPanel[ROWS];
        final JLabel[] labels = new JLabel[ROWS];
        JButton[] buttons = new JButton[ROWS];
        JPanel p = new JPanel(new GridLayout(ROWS,1));
        final JTextField tf = new JTextField(10);
        ActionListener listener = new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            tf.setText(labels[Integer.parseInt(((JButton)ae.getSource()).getName())].getText());
        for(int x = 0; x < ROWS; x++)
          labels[x] = new JLabel(""+(int)(Math.random()*10000));
          buttons[x] = new JButton("Button "+x);
          buttons[x].setName(""+x);
          buttons[x].addActionListener(listener);
          rows[x] = new JPanel(new GridLayout(1,2));
          rows[x].add(labels[x]);
          rows[x].add(buttons[x]);
          p.add(rows[x]);
        JFrame f = new JFrame();
        f.getContentPane().add(p,BorderLayout.CENTER);
        f.getContentPane().add(tf,BorderLayout.SOUTH);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
      public static void main(String[] args)
        SwingUtilities.invokeLater(new Runnable(){
          public void run(){
            new Testing().buildGUI();
    }

  • Problem with KeyAdapter and JButtons in a Jframe

    yes hi
    i have searched almost most of the threads here but nothing
    am trying to make my frame accepts keypress and also have some button on the frame here is the code and thank you for the all the help
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class RPg extends JFrame implements ActionListener
                private int width;
                private int hight;
                public    JPanel north;
                public    JPanel se;
                public    JButton start;
                public    JButton quit;
                public    Screen s;//a Jpanel
                public    KeyStrokeHandler x;
        public RPg() {
               init();
               setTitle("RPG");
               setSize(width,hight);
               setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               setResizable(false);
               setVisible(true);
               x=new KeyStrokeHandler();
             addKeyListener(x);
             public void init() {
               north=new JPanel();
               Container cp = getContentPane();
               s=new Screen();
               this.width=s.width;
               this.hight=s.hight+60;
              start=new JButton("START");
                  start.addActionListener(this);
              quit=new JButton("QUIT");
                  quit.addActionListener(this);
              north.setBackground(Color.DARK_GRAY);
              north.setLayout(new FlowLayout());
              north.add(start);
              north.add(quit);
              cp.add(north, BorderLayout.NORTH);
              cp.add(s, BorderLayout.CENTER);
        public static void main(String[] args) {
            RPg rpg = new RPg();
       public void actionPerformed(ActionEvent ae) {
            if (ae.getActionCommand().equals("QUIT")) {
                     System.exit(0);
            if (ae.getActionCommand().equals("START")) { }
       class KeyStrokeHandler extends KeyAdapter {
               public void keyTyped(KeyEvent ke) {}
               public void keyPressed(KeyEvent ke){
                  int keyCode = ke.getKeyCode();
                  if ((keyCode == KeyEvent.VK_M)){
                     System.out.println("it works");
               public void keyReleased(KeyEvent ke){}

    Use the 'tab' key to navigate through 'contentPane > start > quit' focus cycle. 'M' key works when focus is on contentPane (which it is on first showing). See tutorial pages on 'Using Key Bindings' and 'Focus Subsystem' for more.
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class RPG extends JFrame implements ActionListener {
        private int width;
        private int hight;
        public JPanel north;
        public JPanel se;
        public JButton start;
        public JButton quit;
        public Screen s;    //a Jpanel
        public RPG() {
            init();
            setTitle("RPG");
            setSize(width,hight);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setResizable(false);
            setVisible(true);
        public void init() {
            north=new JPanel();
            Container cp = getContentPane();
            registerKeys((JComponent)cp);
            s=new Screen();
            this.width=s.width;
            this.hight=s.hight+60;
            start=new JButton("START");
                start.addActionListener(this);
            quit=new JButton("QUIT");
                quit.addActionListener(this);
            north.setBackground(Color.DARK_GRAY);
            north.setLayout(new FlowLayout());
            north.add(start);
            north.add(quit);
            cp.add(north, BorderLayout.NORTH);
            cp.add(s, BorderLayout.CENTER);
        public static void main(String[] args) {
            RPG rpg = new RPG();
        public void actionPerformed(ActionEvent ae) {
            if (ae.getActionCommand().equals("QUIT")) {
                     System.exit(0);
            if (ae.getActionCommand().equals("START")) { }
        private void registerKeys(JComponent jc)
            jc.getInputMap().put(KeyStroke.getKeyStroke("M"), "M");
            jc.getActionMap().put("M", mAction);
        Action mAction = new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                System.out.println("it works");
    class Screen extends JPanel {
        int width, hight;
        public Screen() {
            width = 300;
            hight = 300;
            setBackground(Color.pink);
    }

Maybe you are looking for

  • How do you close apps in iOS 7

    How do you close apps in iOS 7. The way I use to do it doesn't  work any more and it is reducing my useful battery life

  • How to resolve the problem in jdeveloper903 oc4j starting:JspTagLib listener error

    I just download a jdeveloper903,i hava a problem: when i start the oc4j alone,it prompt "JspTagLib listener error:null". Then,After depoly the jsp application with JspTag to oc4j,I found the jsp page can not run,but,the jsp application can run in the

  • How Do I Do a Pedestal (Ped) Up Effect in Adobe After Effects

    I'm doing a project using all still photos and I want to transition from the ground to the sky using a blurry ped up movement to make it look like the camera is going up to the sky quickly.  Is there a way to do that with after effects? Not sure of w

  • ALE/IDOC TRANSPORT ERROR FOR Z TABLE

    Dear Experts,                     I am new to ALE/IDOC,I am trying a simple scenario by transporting a ztable data between two clients with in a same server. steps i have done are : 1, created logical system at both sender and receiver. 2, assigned l

  • IPad air cannot install ios 8.0.2

    My 16GB iPad tells me iOS 8.0.2 is available @ 1.3 GB. But - "This update cannot be installed because it requires 7.0 GB of storage.  You can make more storage available by deleting items in Usage Settings." In Usage Settings, 8.3 GB is used and 4.4