JButton and JComboBox problems!!!

I have a program that has a bunch of different panels, and each of those has panels in it and soforth. Several levels down the line I add a JPanel that has a JComboBox, some JButtons and a JTextField. The textfield works fine: you can type in text, etc. However, I cannot click the JButtons (when you mouse over them, they change color appropriately, but clicking does nothing visually, and the ActionListener does not catch anything). In addition, when clicked, the JComboBox displays in a totally inappropriate area!!! (see screenshot below)
http://www.duke.edu/~yv2/JComboBox.JPG <-- SCREENSHOT
Any ideas?

However, I cannot click the JButtons (when you mouse
over them, they change color appropriately, but
clicking does nothing visually, and the
ActionListener does not catch anything).Make sure you have added the ActionListener to the JButton, and provide implementation for the actionPerformed() method.

Similar Messages

  • JButton and JComboBox

    Hi,
    I'm having problems with my comboboxes. Basically, I need that after I press a button, it would take what's selected in the combobox and pass it to database. What would be the sample code for that. Do I need to add ActionListener or ItemListener to the combobox. I'm a little confused with those.
    Thank you

    That's not really how you implement an actionlistener. Whenever the JButton is clicked the actionPeformed method of your actionListener is called. The way you have it set up, you parse what's in the combo box once and then repeatedly send this value off to the database everytime the button is pressed.
    And making a component static just to access almost always constitutes as a bad idea. You can make the DataEntryButton an innerclass. Alternatively you can declare a field in the class and pass along the combo box.
    public DataEntryButton implements ActionListener {
         JComboBox semesters;
        public DataEntryButton(JComboBox semesters) {
            this.semesters = semesters;
        public void actionPerformed(ActionEvent event) {
             int semester = Integer.parseInt((String) semesters.getSelectedItem());
            //and then I send it to DB
    }

  • JButton and exception problem

    Hi all,
    I created a JButton, named open _DB, and add an ActionListener to this. I want that when I click the button the methods in the loop executed (see below for code). However, I always get exceptions. How can I catch these exceptions?
    If I use a try-catch loop I got the error:
    ModelClipTest.java:559: ';' expected
    public void actionPerformed(ActionEvent e)
    ModelClipTest.java:559: missing method body, or declare abstract
    public void actionPerformed(ActionEvent e)
    How can I solve this problem. Can anybody help me?
    Thanks
    Murat
    //CODE
    open_DB.addActionListener
    (new ActionListener()
    public void actionPerformed(ActionEvent e)
    try
    ifcdemo = new IFC_Demo();
    ifcdemo.execute();
    IFC_RelFillsElement_Query.query_fill(ifcdemo);
    IFC_RelVoidsElement_Query.query_void_ids(ifcdemo);
    IFC_BuildingStorey_Query.query_buildingstorey(ifcdemo);
    } //CLOSE TRY
    catch(Exception ex)
    System.out.println("Exception caught");
    System.out.println(":-(");
    } //CLOSE CATCH
    );

    yes, sorry. However, I still get these exceptions for the methods inside.
    What should I do to get rid of these exceptions?
    Thanks.
    ModelClipTest.java:579: unreported exception java.lang.Throwable; must be caught or declared to be thrown
                                  IFC_RelFillsElement_Query.query_fill(ifcdemo);
    ModelClipTest.java:580: unreported exception java.lang.Throwable; must be caught or declared to be thrown
                                  IFC_RelVoidsElement_Query.query_void_ids(ifcdemo);
    ModelClipTest.java:582: unreported exception java.lang.Throwable; must be caught or declared to be thrown
                                  IFC_BuildingStorey_Query.query_buildingstorey(ifcdemo);

  • Java Audio Metronome | Timing and Speed Problems

    Hi all,
    I’m starting to work on a music/metronome application in Java and I’m running into some problems with the timing and speed.
    For testing purposes I’m trying to play two sine wave tones at the same time at regular intervals, but instead they play in sync for a few beats and then slightly out of sync for a few beats and then back in sync again for a few beats.
    From researching good metronome programming, I found that Thread.sleep() is horrible for timing, so I completely avoided that and went with checking System.nanoTime() to determine when the sounds should play.
    I’m using AudioSystem’s SourceDataLine for my audio player and I’m using a thread for each tone that constantly polls System.nanoTime() in order to determine when the sound should play. I create a new SourceDataLine and delete the previous one each time a sound plays, because the volume fluctuates if I leave the line open and keep playing sounds on the same line. I create the player before polling nanoTime() so that the player is already created and all it has to do is play the sound when it is time.
    In theory this seemed like a good method for getting each sound to play on time, but it’s not working correctly.
    At the moment this is just a simple test in Java, but my goal is to create my app on mobile devices (Android, iOS, Windows Phone, etc)...however my current method isn’t even keeping perfect time on a PC, so I’m worried that certain mobile devices with limited resources will have even more timing problems. I will also be adding more sounds to it to create more complex rhythms, so it needs to be able to handle multiple sounds going simultaneously without sounds lagging.
    Another problem I’m having is that the max tempo is controlled by the length of the tone since the tones don’t overlap each other. I tried adding additional threads so that every tone that played would get its own thread...but that really screwed up the timing, so I took it out. I would like to have a way to overlap the previous sound to allow for much higher tempos.
    I posted this question on StackOverflow where I got one reply and my response back explains why I went this direction instead of preloading a larger buffer (which is what they recommended). In short, I did try the buffer method first, but I want to also update a “beat counter” visual display and there was no way to know when the hardware was actually playing the sounds from the buffer. I mentioned that on StackOverflow and I also asked a couple more questions regarding the buffer method, but I haven’t received any more responses.
    http://stackoverflow.com/questions/24110247/java-audio-metronome-timing-and-speed-problems
    Any help getting these timing and speed issues straightened out would be greatly appreciated! Thanks.
    Here is my code...
    SoundTest.java
    import java.awt.*; 
    import java.awt.event.*; 
    import javax.swing.*; 
    import javax.swing.event.*; 
    import java.io.*; 
    import javax.sound.sampled.*; 
    public class SoundTest implements ActionListener { 
        static SoundTest soundTest; 
        // ENABLE/DISABLE SOUNDS 
        boolean playSound1  = true; 
        boolean playSound2  = true; 
        JFrame mainFrame; 
        JPanel mainContent; 
        JPanel center; 
        JButton buttonPlay; 
        int sampleRate = 44100; 
        long startTime;  
        SourceDataLine line = null;  
        int tickLength; 
        boolean playing = false; 
        SoundElement sound01; 
        SoundElement sound02; 
        public static void main (String[] args) {        
            soundTest = new SoundTest(); 
            SwingUtilities.invokeLater(new Runnable() { public void run() { 
                soundTest.gui_CreateAndShow(); 
        public void gui_CreateAndShow() { 
            gui_FrameAndContentPanel(); 
            gui_AddContent(); 
        public void gui_FrameAndContentPanel() { 
            mainContent = new JPanel(); 
            mainContent.setLayout(new BorderLayout()); 
            mainContent.setPreferredSize(new Dimension(500,500)); 
            mainContent.setOpaque(true); 
            mainFrame = new JFrame("Sound Test");                
            mainFrame.setContentPane(mainContent);               
            mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
            mainFrame.pack(); 
            mainFrame.setVisible(true); 
        public void gui_AddContent() { 
            JPanel center = new JPanel(); 
            center.setOpaque(true); 
            buttonPlay = new JButton("PLAY / STOP"); 
            buttonPlay.setActionCommand("play"); 
            buttonPlay.addActionListener(this); 
            buttonPlay.setPreferredSize(new Dimension(200, 50)); 
            center.add(buttonPlay); 
            mainContent.add(center, BorderLayout.CENTER); 
        public void actionPerformed(ActionEvent e) { 
            if (!playing) { 
                playing = true; 
                if (playSound1) 
                    sound01 = new SoundElement(this, "Sound1", 800, 1); 
                if (playSound2) 
                    sound02 = new SoundElement(this, "Sound2", 1200, 1); 
                startTime = System.nanoTime(); 
                if (playSound1) 
                    new Thread(sound01).start(); 
                if (playSound2) 
                    new Thread(sound02).start(); 
            else { 
                playing = false; 
    SoundElement.java
    import java.io.*; 
    import javax.sound.sampled.*; 
    public class SoundElement implements Runnable { 
        SoundTest soundTest; 
        // TEMPO CHANGE 
        // 750000000=80bpm | 300000000=200bpm | 200000000=300bpm 
        long nsDelay = 750000000; 
        long before; 
        long after; 
        long diff; 
        String name=""; 
        int clickLength = 4100;  
        byte[] audioFile; 
        double clickFrequency; 
        double subdivision; 
        SourceDataLine line = null; 
        long audioFilePlay; 
        public SoundElement(SoundTest soundTestIn, String nameIn, double clickFrequencyIn, double subdivisionIn){ 
            soundTest = soundTestIn; 
            name = nameIn; 
            clickFrequency = clickFrequencyIn; 
            subdivision = subdivisionIn; 
            generateAudioFile(); 
        public void generateAudioFile(){ 
            audioFile = new byte[clickLength * 2]; 
            double temp; 
            short maxSample; 
            int p=0; 
            for (int i = 0; i < audioFile.length;){ 
                temp = Math.sin(2 * Math.PI * p++ / (soundTest.sampleRate/clickFrequency)); 
                maxSample = (short) (temp * Short.MAX_VALUE); 
                audioFile[i++] = (byte) (maxSample & 0x00ff);            
                audioFile[i++] = (byte) ((maxSample & 0xff00) >>> 8); 
        public void run() { 
            createPlayer(); 
            audioFilePlay = soundTest.startTime + nsDelay; 
            while (soundTest.playing){ 
                if (System.nanoTime() >= audioFilePlay){ 
                    play(); 
                    destroyPlayer(); 
                    createPlayer();              
                    audioFilePlay += nsDelay; 
            try { destroyPlayer(); } catch (Exception e) { } 
        public void createPlayer(){ 
            AudioFormat af = new AudioFormat(soundTest.sampleRate, 16, 1, true, false); 
            try { 
                line = AudioSystem.getSourceDataLine(af); 
                line.open(af); 
                line.start(); 
            catch (Exception ex) { ex.printStackTrace(); } 
        public void play(){ 
            line.write(audioFile, 0, audioFile.length); 
        public void destroyPlayer(){ 
            line.drain(); 
            line.close(); 

    Thanks but you have never posted reply s0lutions before ?? And F 4 is definitely not 10 times faster as stated before I upgraded !!

  • JBuilder 8 and GUI Problems

    I have an abstract base class that extends JFrame. It's not in a package and is directly in my project.
    The base class has some JPanels, JButtons, and JLabels. I create a class and derive from the base class, and the derived class adds a JButton and a few private methods. Everything compiles fine and
    the program runs fine.
    The problem is when I click F12 to go into designer mode for the derived class to view the GUI, I see a red dialog with the name of the base class in the upper-left corner, and this message in the bottom of the IDE:
    Failed to create live instance for variable 'this'. null
    Failed to create live visual subcomponent this as BaseFrame(cls); creating a red component in its place
    I've tried everything, and have the latest JBuilder8 patch.
    Can anyone help with this? I have seen one other person on the web with the same exact problem, but he got zero responses indicating it's probably difficult to solve the issue.

    I found out why this is happening, but I don't yet know how to fix it. It's a start.
    The reason the derived class does not show the JFrame in the Design mode is
    that the base class is an abstract class. When I remove the abstract keyword
    from the base class, it works and I can view the JFrame in Design mode for the derived class.
    Now to figure out how to keep the base class abstract and still have design mode work.

  • Strange JComboBox problem

    I have a weird JComboBox problem that has me stumped. I am dynamically changing the contents of a JComboBox after creation. When the change function is called it removes all existing contents from the JComboBox and then repopulates it. It is really straight forward. The strange thing is that it is working perfectly under Windows 2000 with JRE build 1.3.0, but with Windows XP I end up an empty JComboBox. I don't even know where to start debugging this. Any ideas?
    Thanks

    I notice the same problem... with no solution for the moment...

  • Numbers on JButtons and set JButtons to Opaque

    Hi everyone:
    please check for me why numbers(like 1 to 35) don't appears on JButtons, and why I setOpaque(true) to JButtons, it doesn't work. Thanks
    // why I can not see the numbers (1 to 35) in JButtons ????????????
    // and how can I operate setOpaque(true) to JButtons.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.GridLayout;
    public class DrawCalendar extends JPanel{
         private static DrawCalendar dC;
         private static JButton jB1,jB2,jB3;
         private static Dimension dMS;
         private static GridLayout gL;
         private static Container c;
         // why I can not see the numbers (1 to 35) in JButtons ????????????
         public DrawCalendar(){
              JButton j= new JButton("1");
         gL=new GridLayout(5,7,4,4);
              setLayout(gL);
    add(j);
    add(new JButton("2"));
    add(new JButton("3"));
    add(new JButton("4"));
    add(new JButton("5"));
    add(new JButton("6"));
    add(new JButton("7"));
    add(new JButton("8"));
    add(new JButton("9"));
    add(new JButton("10"));
    add(new JButton("11"));
    add(new JButton("12"));
    add(new JButton("12"));
    add(new JButton("14"));
    add(new JButton("15"));
    add(new JButton("16"));
    add(new JButton("17"));
    add(new JButton("18"));
    add(new JButton("19"));
    add(new JButton("20"));
    add(new JButton("21"));
    add(new JButton("22"));
    add(new JButton("23"));
    add(new JButton("24"));
    add(new JButton("25"));
    add(new JButton("26"));
    add(new JButton("27"));
    add(new JButton("28"));
    add(new JButton("29"));
    add(new JButton("30"));
    add(new JButton("31"));
    add(new JButton("32"));
    add(new JButton("33"));
    add(new JButton("34"));
    add(new JButton("35"));
    import java.awt.*;
    import java.awt.Color;
    import javax.swing.*;
    import javax.swing.JButton;
    import javax.swing.JMenuBar;
    public class TestMain extends JFrame{
    private static JButton b1, b2, b3;
    private static TestMain tM;
         private static JPanel jP;
    private static Container c;
    private static DrawCalendar dC;
         public static void main(String[] args){
         tM = new TestMain();
         addItems();
         tM.setVisible(true);
         public TestMain(){
         super(" Test");
         dC=new DrawCalendar();
         setSize(600,600);
    //set up layoutManager
    c=getContentPane();
    c.setLayout ( new GraphPaperLayout(new Dimension (8,20)));
    //set up three Button and one JPanel
    b1=new JButton("1");
    b1.setOpaque(true);
    b2=new JButton("2");
    b2.setOpaque(true);
    b3=new JButton("3");
    b3.setOpaque(true);
    //add the munuBar, the Jpanel and three JButtons
    public static void addItems(){
         c.add(b1, new Rectangle(5,0,1,1));
         c.add(b2, new Rectangle(6,0,1,1));
    c.add(b3, new Rectangle(7,0,1,1));
         c.add(dC, new Rectangle(5,1,3,5));
    import java.awt.*;
    import java.util.Hashtable;
    import java.io.*;
    * The <code>GraphPaperLayout</code> class is a layout manager that
    * lays out a container's components in a rectangular grid, similar
    * to GridLayout. Unlike GridLayout, however, components can take
    * up multiple rows and/or columns. The layout manager acts as a
    * sheet of graph paper. When a component is added to the layout
    * manager, the location and relative size of the component are
    * simply supplied by the constraints as a Rectangle.
    * <p><code><pre>
    * import java.awt.*;
    * import java.applet.Applet;
    * public class ButtonGrid extends Applet {
    * public void init() {
    * setLayout(new GraphPaperLayout(new Dimension(5,5)));
    * // Add a 1x1 Rect at (0,0)
    * add(new Button("1"), new Rectangle(0,0,1,1));
    * // Add a 2x1 Rect at (2,0)
    * add(new Button("2"), new Rectangle(2,0,2,1));
    * // Add a 1x2 Rect at (1,1)
    * add(new Button("3"), new Rectangle(1,1,1,2));
    * // Add a 2x2 Rect at (3,2)
    * add(new Button("4"), new Rectangle(3,2,2,2));
    * // Add a 1x1 Rect at (0,4)
    * add(new Button("5"), new Rectangle(0,4,1,1));
    * // Add a 1x2 Rect at (2,3)
    * add(new Button("6"), new Rectangle(2,3,1,2));
    * </pre></code>
    * @author Michael Martak
    * Updated by Judy Bowen, September 2002 to allow serialization
    public class GraphPaperLayout implements LayoutManager2, Serializable{
    int hgap; //horizontal gap
    int vgap; //vertical gap
    Dimension gridSize; //grid size in logical units (n x m)
    Hashtable compTable; //constraints (Rectangles)
    * Creates a graph paper layout with a default of a 1 x 1 graph, with no
    * vertical or horizontal padding.
    public GraphPaperLayout() {
    this(new Dimension(1,1));
    * Creates a graph paper layout with the given grid size, with no vertical
    * or horizontal padding.
    public GraphPaperLayout(Dimension gridSize) {
    this(gridSize, 0, 0);
    * Creates a graph paper layout with the given grid size and padding.
    * @param gridSize size of the graph paper in logical units (n x m)
    * @param hgap horizontal padding
    * @param vgap vertical padding
    public GraphPaperLayout(Dimension gridSize, int hgap, int vgap) {
    if ((gridSize.width <= 0) || (gridSize.height <= 0)) {
    throw new IllegalArgumentException(
    "dimensions must be greater than zero");
    this.gridSize = new Dimension(gridSize);
    this.hgap = hgap;
    this.vgap = vgap;
    compTable = new Hashtable();
    * @return the size of the graph paper in logical units (n x m)
    public Dimension getGridSize() {
    return new Dimension( gridSize );
    * Set the size of the graph paper in logical units (n x m)
    public void setGridSize( Dimension d ) {
    setGridSize( d.width, d.height );
    * Set the size of the graph paper in logical units (n x m)
    public void setGridSize( int width, int height ) {
    gridSize = new Dimension( width, height );
    public void setConstraints(Component comp, Rectangle constraints) {
    compTable.put(comp, new Rectangle(constraints));
    * Adds the specified component with the specified name to
    * the layout. This does nothing in GraphPaperLayout, since constraints
    * are required.
    public void addLayoutComponent(String name, Component comp) {
    * Removes the specified component from the layout.
    * @param comp the component to be removed
    public void removeLayoutComponent(Component comp) {
    compTable.remove(comp);
    * Calculates the preferred size dimensions for the specified
    * panel given the components in the specified parent container.
    * @param parent the component to be laid out
    * @see #minimumLayoutSize
    public Dimension preferredLayoutSize(Container parent) {
    return getLayoutSize(parent, true);
    * Calculates the minimum size dimensions for the specified
    * panel given the components in the specified parent container.
    * @param parent the component to be laid out
    * @see #preferredLayoutSize
    public Dimension minimumLayoutSize(Container parent) {
    return getLayoutSize(parent, false);
    * Algorithm for calculating layout size (minimum or preferred).
    * <p>
    * The width of a graph paper layout is the largest cell width
    * (calculated in <code>getLargestCellSize()</code> times the number of
    * columns, plus the horizontal padding times the number of columns
    * plus one, plus the left and right insets of the target container.
    * <p>
    * The height of a graph paper layout is the largest cell height
    * (calculated in <code>getLargestCellSize()</code> times the number of
    * rows, plus the vertical padding times the number of rows
    * plus one, plus the top and bottom insets of the target container.
    * @param parent the container in which to do the layout.
    * @param isPreferred true for calculating preferred size, false for
    * calculating minimum size.
    * @return the dimensions to lay out the subcomponents of the specified
    * container.
    * @see java.awt.GraphPaperLayout#getLargestCellSize
    protected Dimension getLayoutSize(Container parent, boolean isPreferred) {
    Dimension largestSize = getLargestCellSize(parent, isPreferred);
    Insets insets = parent.getInsets();
    largestSize.width = ( largestSize.width * gridSize.width ) +
    ( hgap * ( gridSize.width + 1 ) ) + insets.left + insets.right;
    largestSize.height = ( largestSize.height * gridSize.height ) +
    ( vgap * ( gridSize.height + 1 ) ) + insets.top + insets.bottom;
    return largestSize;
    * Algorithm for calculating the largest minimum or preferred cell size.
    * <p>
    * Largest cell size is calculated by getting the applicable size of each
    * component and keeping the maximum value, dividing the component's width
    * by the number of columns it is specified to occupy and dividing the
    * component's height by the number of rows it is specified to occupy.
    * @param parent the container in which to do the layout.
    * @param isPreferred true for calculating preferred size, false for
    * calculating minimum size.
    * @return the largest cell size required.
    protected Dimension getLargestCellSize(Container parent,
    boolean isPreferred) {
    int ncomponents = parent.getComponentCount();
    Dimension maxCellSize = new Dimension(0,0);
    for ( int i = 0; i < ncomponents; i++ ) {
    Component c = parent.getComponent(i);
    Rectangle rect = (Rectangle)compTable.get(c);
    if ( c != null && rect != null ) {
    Dimension componentSize;
    if ( isPreferred ) {
    componentSize = c.getPreferredSize();
    } else {
    componentSize = c.getMinimumSize();
    // Note: rect dimensions are already asserted to be > 0 when the
    // component is added with constraints
    maxCellSize.width = Math.max(maxCellSize.width,
    componentSize.width / rect.width);
    maxCellSize.height = Math.max(maxCellSize.height,
    componentSize.height / rect.height);
    return maxCellSize;
    * Lays out the container in the specified container.
    * @param parent the component which needs to be laid out
    public void layoutContainer(Container parent) {
    synchronized (parent.getTreeLock()) {
    Insets insets = parent.getInsets();
    int ncomponents = parent.getComponentCount();
    if (ncomponents == 0) {
    return;
    // Total parent dimensions
    Dimension size = parent.getSize();
    int totalW = size.width - (insets.left + insets.right);
    int totalH = size.height - (insets.top + insets.bottom);
    // Cell dimensions, including padding
    int totalCellW = totalW / gridSize.width;
    int totalCellH = totalH / gridSize.height;
    // Cell dimensions, without padding
    int cellW = (totalW - ( (gridSize.width + 1) * hgap) )
    / gridSize.width;
    int cellH = (totalH - ( (gridSize.height + 1) * vgap) )
    / gridSize.height;
    for ( int i = 0; i < ncomponents; i++ ) {
    Component c = parent.getComponent(i);
    Rectangle rect = (Rectangle)compTable.get(c);
    if ( rect != null ) {
    int x = insets.left + ( totalCellW * rect.x ) + hgap;
    int y = insets.top + ( totalCellH * rect.y ) + vgap;
    int w = ( cellW * rect.width ) - hgap;
    int h = ( cellH * rect.height ) - vgap;
    c.setBounds(x, y, w, h);
    // LayoutManager2 /////////////////////////////////////////////////////////
    * Adds the specified component to the layout, using the specified
    * constraint object.
    * @param comp the component to be added
    * @param constraints where/how the component is added to the layout.
    public void addLayoutComponent(Component comp, Object constraints) {
    if (constraints instanceof Rectangle) {
    Rectangle rect = (Rectangle)constraints;
    if ( rect.width <= 0 || rect.height <= 0 ) {
    throw new IllegalArgumentException(
    "cannot add to layout: rectangle must have positive width and height");
    if ( rect.x < 0 || rect.y < 0 ) {
    throw new IllegalArgumentException(
    "cannot add to layout: rectangle x and y must be >= 0");
    setConstraints(comp, rect);
    } else if (constraints != null) {
    throw new IllegalArgumentException(
    "cannot add to layout: constraint must be a Rectangle");
    * Returns the maximum size of this component.
    * @see java.awt.Component#getMinimumSize()
    * @see java.awt.Component#getPreferredSize()
    * @see LayoutManager
    public Dimension maximumLayoutSize(Container target) {
    return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
    * Returns the alignment along the x axis. This specifies how
    * the component would like to be aligned relative to other
    * components. The value should be a number between 0 and 1
    * where 0 represents alignment along the origin, 1 is aligned
    * the furthest away from the origin, 0.5 is centered, etc.
    public float getLayoutAlignmentX(Container target) {
    return 0.5f;
    * Returns the alignment along the y axis. This specifies how
    * the component would like to be aligned relative to other
    * components. The value should be a number between 0 and 1
    * where 0 represents alignment along the origin, 1 is aligned
    * the furthest away from the origin, 0.5 is centered, etc.
    public float getLayoutAlignmentY(Container target) {
    return 0.5f;
    * Invalidates the layout, indicating that if the layout manager
    * has cached information it should be discarded.
    public void invalidateLayout(Container target) {
    // Do nothing

    Hello,
    I think you have really a problem with this layout.
    Please first check the standard [url http://java.sun.com/docs/books/tutorial/uiswing/layout/using.html]LayoutManager.
    JButtons are opaque usually and they will be shown if you use another LayoutManager:import java.awt.*;
    import javax.swing.*;
    class DrawCalendar extends JPanel
         private static DrawCalendar dC;
         private static JButton jB1, jB2, jB3;
         private static Dimension dMS;
         private static GridLayout gL;
         private static Container c;
         // why I can not see the numbers (1 to 35) in JButtons ????????????
         public DrawCalendar()
              JButton j = new JButton("1");
              gL = new GridLayout(5, 7, 4, 4);
              setLayout(gL);
              add(j);
              add(new JButton("2"));
              add(new JButton("3"));
              add(new JButton("4"));
              add(new JButton("5"));
              add(new JButton("6"));
              add(new JButton("7"));
              add(new JButton("8"));
              add(new JButton("9"));
              add(new JButton("10"));
              add(new JButton("11"));
              add(new JButton("12"));
              add(new JButton("12"));
              add(new JButton("14"));
              add(new JButton("15"));
              add(new JButton("16"));
              add(new JButton("17"));
              add(new JButton("18"));
              add(new JButton("19"));
              add(new JButton("20"));
              add(new JButton("21"));
              add(new JButton("22"));
              add(new JButton("23"));
              add(new JButton("24"));
              add(new JButton("25"));
              add(new JButton("26"));
              add(new JButton("27"));
              add(new JButton("28"));
              add(new JButton("29"));
              add(new JButton("30"));
              add(new JButton("31"));
              add(new JButton("32"));
              add(new JButton("33"));
              add(new JButton("34"));
              add(new JButton("35"));
    public class TestMain extends JFrame
         private static JButton b1, b2, b3;
         private static TestMain tM;
         private static JPanel jP;
         private static Container c;
         private static DrawCalendar dC;
         public static void main(String[] args)
              tM = new TestMain();
              addItems();
              tM.setVisible(true);
         public TestMain()
              super(" Test");
              dC = new DrawCalendar();
              setSize(600, 600);
              //set up layoutManager
              c = getContentPane();
              c.setLayout(new FlowLayout());
              //set up three Button and one JPanel
              b1 = new JButton("1");
              b1.setOpaque(true);
              b2 = new JButton("2");
              b2.setOpaque(true);
              b3 = new JButton("3");
              b3.setOpaque(true);
         //add the munuBar, the Jpanel and three JButtons
         public static void addItems()
              c.add(b1);
              c.add(b2);
              c.add(b3);
              c.add(dC);
    }regards
    Tim

  • Colors of JSpinner and JComboBox

    hello
    I like to change the fore- and backgroundcolors of JSpinner and JComboBox. how can I do this?
    thanks in advance! nix

    this is much easyer code I will use it.
    but the button is anyway gray and black!?You want to change the color of the arrowButton and arrow color?
    there's probably an easier way, but this worked OK for me
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.plaf.basic.BasicSpinnerUI;
    import javax.swing.plaf.basic.BasicArrowButton;
    class Testing extends JFrame
      public Testing()
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocation(400,300);
        JSpinner spinner = new JSpinner(new SpinnerNumberModel(50, 0, 100, 5));
        spinner.setUI(new MyUI());
        ((JSpinner.DefaultEditor)spinner.getEditor()).getTextField().setBackground(Color.GREEN);
        JPanel jp = new JPanel();
        jp.add(spinner);
        getContentPane().add(jp);
        pack();
      public static void main(String[] args) {new Testing().setVisible(true);}
    class MyUI extends BasicSpinnerUI
      protected Component createNextButton()
        JButton btn = (JButton)super.createNextButton();
        JButton btnNext = new MyBasicArrowButton(SwingConstants.NORTH);
        btnNext.addActionListener(btn.getActionListeners()[0]);
        btnNext.setBackground(Color.BLACK);
        return btnNext;
      protected Component createPreviousButton()
        JButton btn = (JButton)super.createPreviousButton();
        JButton btnPrevious = new MyBasicArrowButton(SwingConstants.SOUTH);
        btnPrevious.addActionListener(btn.getActionListeners()[0]);
        btnPrevious.setBackground(Color.BLACK);
        return btnPrevious;
    class MyBasicArrowButton extends BasicArrowButton
      public MyBasicArrowButton(int direction)
        super(direction);
      public MyBasicArrowButton(int direction,Color background,Color shadow,Color darkShadow,Color highlight)
        super(direction,background,shadow,darkShadow,highlight);
      public void paintTriangle(Graphics g,int x,int y,int size,int direction,boolean isEnabled)
        Color oldColor = g.getColor();//Note 1: all if(!isEnabled) code removed, for brevity
        int mid, i, j;                //Note 2: all EAST / WEST code removed, for brevity
        j = 0;
        size = Math.max(size, 2);
        mid = (size / 2) - 1;
        g.translate(x, y);
        g.setColor(Color.GREEN);//<-------------------set arrow colors here
        switch(direction)
          case NORTH:
            for(i = 0; i < size; i++)
              g.drawLine(mid-i, i, mid+i, i);
            break;
          case SOUTH:
            j = 0;
            for(i = size-1; i >= 0; i--)
              g.drawLine(mid-i, j, mid+i, j);
              j++;
            break;
        g.translate(-x, -y);
        g.setColor(oldColor);
    }

  • I am not able to launch FF everytime i tr to open it, it says FF has to submit a crash report, i even tried doing that and the report was submitted too, but stiil FF did not start, and the problem still persists, please help me solve this issue in English

    Question
    I am not able to launch FF everytime i try to open it, it says FF has to submit a crash report,and restore yr tabs. I even tried doing that and the report was submitted too, but still FF did not start, and the problem still persists, please help me solve this issue
    '''(in English)'''

    Hi Danny,
    Per my understanding that you can't get the expect result by using the expression "=Count(Fields!TICKET_STATUS.Value=4) " to count the the TICKET_STATUS which value is 4, the result will returns the count of all the TICKET_STATUS values(206)
    but not 180, right?
    I have tested on my local environment and can reproduce the issue, the issue caused by you are using the count() function in the incorrect way, please modify the expression as below and have a test:
    =COUNT(IIF(Fields!TICKET_STATUS.Value=4 ,1,Nothing))
    or
    =SUM(IIF(Fields!TICKET_STATUS=4,1,0))
    If you still have any problem, please feel free to ask.
    Regards,
    Vicky Liu
    Vicky Liu
    TechNet Community Support

  • BOSD, Battery issues and Heating problem after iOS 8 upgrade

    i have upgraded my iPad mini to iOS 8. Ever since I upgraded to iOS 8 am facing blue screen issues and heating problem as well. This is really frustrating even the patch iOS 8.0.2 dint solve the problem. Are you guys listening our complaints. When will you fixing it.

    The same thing happened to me on my 2012 Subaru Outback.  I'm not sure this will help you since you have a Honda, but I'm posting this just in case.
    I paired the audio on my car with my iPhone 6.  However, when I turned the car off and back on again, the iPhone would not pair automatically.  I had to manually connect the iPhone with the car.  Turns out there are two separate bluetooth pairings on my car: one for phone which allows up to 5 devices and one for audio which allows only one device.  So I did the second bluetooth pairing for the phone (had already done the audio), and that fixed it.  YMMV

  • I am making code to try to make a game and my problem is that my code......

    I am making code to try to make a game and my problem is that my code
    will not let it change the hit everytime so im getting the first guy to hit 1 then next hits 8 and so on and always repeats.
    Another problem is that I would like it to attack with out me telling it how much times to attack. I am using Object oriented programming.
    Here is the code for my objects:
    import java.lang.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.util.Random;
    import static java.lang.Math.*;
    import java.awt.*;
    import java.awt.color.*;
    class rockCrab {
         //Wounding formula
         double sL = 70;                                   // my Strength Level
         double bP = 1;                                   // bonus for prayer (is 1 times prayer bonus)
         double aB = 0;                                 // equipment stats
         double eS = (sL * bP) + 3;                         // effective strength
         double bD = floor(1.3 + (eS/10) + (aB/80) + ((eS*aB)/640));     // my base damage
         //Attack formula
         double aL = 50;                                   // my Attack Level
         double eD = 1;                                   // enemy's Defence
         double eA = aL / eD;                              // effective Attack
         double eB = 0;                                   // equipment bonus'
         double bA = ((eA/10) * (eB/10));                    // base attack
         //The hit formula
         double fA = random() * bA;
         double fH = random() * bD;
         double done = rint(fH - fA);
         //health formula
         double health = floor(10 + sL/10 * aL/10);
         rockCrab() {
         void attack() {
              health = floor(10 + sL/10 * aL/10);
              double done = rint(fH - fA);
              fA = random() * bA;
              fH = random() * bD;
              done = rint(fH - fA);
              System.out.println("Rockcrab hit" +done);
    import java.lang.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.util.Random;
    import static java.lang.Math.*;
    import java.awt.*;
    import java.awt.color.*;
    class self {
         //Wounding formula
         double sL = 1;                                   // my Strength Level
         double bP = 1;                                   // bonus for prayer (is 1 times prayer bonus)
         double aB = 0;                                 // equipment stats
         double eS = (sL * bP) + 3;                         // effective strength
         double bD = floor(1.3 + (eS/10) + (aB/80) + ((eS*aB)/640));     // my base damage
         //Attack formula
         double aL = 1;                                   // my Attack Level
         double eD = 1;                                   // enemy's Defence
         double eA = aL / eD;                              // effective Attack
         double eB = 0;                                   // equipment bonus'
         double bA = ((eA/10) * (eB/10));                    // base attack
         //The hit formula
         double fA = random() * bA;
         double fH = random() * bD;
         double done = rint(fH - fA);
         //health formula
         double health = floor(10 + sL/10 * aL/10);
         self() {
         void attack() {
              health = floor(10 + sL/10 * aL/10);
              fA = random() * bA;
              fH = random() * bD;
              done = rint(fH - fA);
              System.out.println("You hit" +done);
    }Here is the main code that writes what the objects do:
    class fight {
         public static void main(String[] args) {
              self instance1 = new self();
              rockCrab instance2 = new rockCrab();
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
              instance2.health = instance2.health - instance1.done;
              System.out.println("You hit: " +instance1.done);
              System.out.println("rockCrabs health: " + instance2.health);
              instance1.health = instance1.health - instance2.done;
              System.out.println("RockCrab hit: " +instance2.done);
              System.out.println("rockCrabs health: " + instance1.health);
    }when the code is run it says something like this:
    you hit 1
    RockCrabs health is 9
    RockCrab hit 7
    your health is 38
    you hit 1
    RockCrabs health is 8
    RockCrab hit 7
    your health is 31
    you hit 1
    RockCrabs health is 7
    RockCrab hit 7
    your health is 24
    you hit 1
    RockCrabs health is 6
    RockCrab hit 7
    your health is 17
    my point is whatever some one hits it always repeats that
    my expected output would have to be something like
    you hit 1
    RockCrabs health is 9
    RockCrab hit 9
    your health is 37
    you hit 3
    RockCrabs health is 6
    RockCrab hit 4
    your health is 33
    you hit 2
    RockCrabs health is 4
    RockCrab hit 7
    your health is 26
    you hit 3
    RockCrabs health is 1
    RockCrab hit 6
    your health is 20
    Edited by: rade134 on Jun 4, 2009 10:58 AM

    [_Crosspost_|http://forums.sun.com/thread.jspa?threadID=5390217] I'm locking.

  • Remote and IR Problem

    A rather odd and annoying problem has recently been occuring on my MBP. A couple days ago my remote (after working without fail for over a year now) suddenly stopped working. Yesterday night and this morning it started working again but after a while it stopped again. I've read dozens of support articles which haven't really helped because there seems to be another problem.
    Most articles have stated that there is an option to disable the IR receiver in the "security" window under system preferences. When the IR and remote are not working this option disappears but when they are working the option is present. I have also tried replacing the battery without any result.
    I am now thinking that it might have something to do with heat buildup because it is mainly occuring after the laptop has been on for about a half hour, so I am going to try to borrow someone's fan.
    If anyone has any suggestions to solve this I would appreciate it if you could help. Thanks!
    MacBook Pro 1.83 GHz   Mac OS X (10.4.9)  

    check out this thread. Seems to be the same problem.
    http://discussions.apple.com/thread.jspa?messageID=4701905&#4701905

  • LG Ally text message and gps problems

    hello. ive been with verizon for about 10 years maybe. ive been overall happy with the service and customer service. but the prices should be alot lower.lol. i started out with the motorolas then switched to the lg phones. only problem with the motorola was the speakers. not loud enough. could never hear the phone ring. the lgs usually suffer from the same problem.
    i had a few phone problems but nothing like this lg ally. im on my second one and about to be my 3rd one in about 3 months. 1st phone i had every problem under the sun. this phone i am suffering from text message problems and gps problems. i suffer from what everyone else has problems with. the messages wont send. they will eventually lock up. it will show the envelope with the red explanation point ( i think thats the graphic). then usually everytime when i sent a text the texts will close. it will send then bounce back and show up as a draft and i have to resend it and wait for it to go thru. finally the last problem with the texts. when i send a text a phone number from my contacts shows up and freezes on the screen. its in white text with a black background. its the same number every time. it stays on the screen until i restart or pull my battery out.
    gps. when i open up google gps that comes with the phone i make sure the gps is on... when the directions are found and the map pops up 9 out of 10 times it just keeps saying searching for gps. the turn by turn never is found. the 1 time it does it takes a good 10 minutes to be found. atleast on my first one ally the gps did work 8 out of 10 times. it just took a good 5-10 minutes for gps to be found and show turn by turn.
    anyone else have these problems? where you able to fix them or did you need to get a new phone? the 2.1 update was supposed to fix problems. i think they just made it worse. the ally is supposed to have 2.2 froyo. where is it. is it ever going to get it. i got this phone because i like the lgs and the keyboard. also the sales representative on the phone was giving the lg ally rave reviews. why couldnt he say dont buy this go with a motorola droid. this phone is the biggest junk ever made

    I do apologize you are having trouble with your device I looked in our information system on the LG Ally in reguards to issues you are having it states if you have the Free Droid Security anti virus protection application down loaded it will cause the phone to lock up or freeze. Check and make sure you do not have the application on your device. Check you GPS settings and make sure correct. Go to Settings; Location & Security; make sure GPS is on wireless network. If this does not fix issue you can try doing a Master Reset on your device. Make sure your contacts are saved in your G-mail account or through Back Up Assistance.
    Master Reset/Soft Reset:
    Factory Reset option 1
    From the main screen, touch menu tab
    Touch Settings
    Touch Privacy
    Touch Factory Data reset
    Touch Reset Phone
    Warning: This will erase all data from your phone, including:
    Your Google account
    System and application data and settings
    Downloaded Applications
    It will not erase: Current System software and bundled applications; SD Card files, such as music or Photos
    Factory Reset option 2  - Warning this will reset device back to original factory settings.
    Turn off the phone
    Press and hold "home" + "end" + "volume up or down" keys together for a few seconds when the device is power off
    Once device displays boot information, release keys.
    Soft Reset
    Press the Power key.
    Touch Power off.
    Touch OK.
    Press the Power key to power on the device.
    or
    Remove battery cover, remove battery and reinstall.Also there is a new update for LG Ally it will be the Froyo 2.2 but there is not release date available at this time it will post on your device when available. Hope this Helps. Leslie

  • I am deleting files through my trash in my macbook pro (2010) and then emptying the trash can, but my hard disk space is not increasing! i recently upgraded to lion and the problem is new, wasn't the same with snow leopard! HELP!!!!!

    i am deleting files through my trash in my macbook pro (2010) and then emptying the trash can, but my hard disk space is not increasing! i recently upgraded to lion and the problem is new, wasn't the same with snow leopard! HELP!!!!!
    When i press command+I (Get Info) i see that there is 140 GB "Available Space" on my hard disk but when i click on my hard disk icon on the desktop, and then press "space" i only see 102 GB free!! What the f*???
    Please HELP!!!!!! Getting second thoughts on Lion!!!!

    Hi b,
    Have you restarted yet?

  • How do I fix my ipod classic that says very low batter after I have charged it and the problem persists?

    I have an Ipod video 30g that says Please wait very low battery. I charged it for about a day and the problem persists. I've tried using some solutions on the internet and none of them worked including: holding the menu and select, holding select and play to put it in disk mode with no avail. Is there anyone who can help me!!!

    Have you read this post written by another forum member?
    The Sad iPod icon.
    However, as your iPod was purchased on Boxing Day, why not get it serviced under the warranty?
    You can arrange online service here.
    Service request.
    Or if an Apple store is near you, take it there and have them check your iPod.
    You can make an appointment by using this link.
    Genius Bar Appointments.

Maybe you are looking for

  • My Safari keeps restarting, even after a clean install of OSX Mountain Lion

    Even after a clean install of OS X, it restarts like almost all the time. Sometimes after a crash, I launch the app with only a page loaded and it crashes too. Tried some of the suggestions but it still crashes. Someone please help me. The crash repo

  • How activate bluetooth manager on Satellite P200-1C7

    I have installed a bluetooth dongle on my Toshiba Satellite P200- 1C7 so I have downloaded bluetooth manager and bluetooth stack. Or when I tried to use bluetooth manager it said that it remains 25 days of evaluation. So I wanted to know how activate

  • Performance Tunning - Oracle Reports 6i

    Hi Gurus, I have an Oracle Apps Reports 6i with a formula column having so much of conditions making the reports to take long time to get completed. Its taking 20 mins to complete. Please your help on this. Thanks, Genoo

  • Acrobat 5.05 Distiller not Producing .pdf Files

    When I first purchased Acrobat 5.05 and installed it, to produce a .pdf file from an application, I printed the file from the application choosing Acrobat Distiller as the printer.  This prompted for a file name and location.  When the OK button was

  • Best Practice - Battery - Lenovo S440

    Hi Forum, I have recently purchased the S440 which is a very well built device. Whilst using it, I have noticed that when the laptop is powered down (not sleep) and the PSU is switched off at the mains, the laptop battery will continue to drain. So t