I am using netbeans compiler ver 7.11.
I am trying to create a GridLayout but it showing an error
in the lines where I write the code to create buttons for the Layout.
It gives the below errors
no suitable constructor found for JButton(Java.lang.String.java.lang.String)
Constructor javax.swing.JButton.JButton(java.lang.String,javax.swing.Icon)is not applicable
(actual argument Java.lang.String cannot be converted to javax.swing.Icon by method
invocation conversion)
Constructor javax.swing.JButton.JButton(javax.swing.Action)is not applicable
(actual and formal argument lists differ in length)
Constructor javax.swing.JButton.JButton(java.lang.String)is not applicable
(actual and formal argument lists differ in length)
Constructor javax.swing.JButton.JButton(javax.swing.Icon)is not applicable
(actual and formal argument lists differ in length)
Constructor javax.swing.JButton.JButton()is not applicable
(actual and formal argument lists differ in length)
It shows these error from line 7 to line 11. Below is the code That I entered into Java Netbeans compiler.
import java.awt.*;
import javax.swing.*;
public class Griddemo extends JFrame{
public Griddemo()
{
setLayout(new GridLayout(3,2));
add(new JButton("Row-1","Col-1")); ---- line7
add(new JButton("Row-1","Col-2")); ---- line8
add(new JButton("Row-2","Col-1")); ---- line9
add(new JButton("Row-2","Col-2")); ---- line10
add(new JButton("Row-3","Col-1")); ---- line11
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public static void main(String args[])
{
new Griddemo();
}
}
The problem you seem to be facing is that you are passing into
JButton2Strings, and there is no constructor with that signature. try thismaking each button label as descriptive, but with a single
String.