mb007
asked on
Simple Java Error
What is wrong with the following Line ??? I know its something simple.... Can anyone help me out. Thanx guys
void jButton1_actionPerformed(A ctionEvent e) {
pageTA.setFont(new java.awt.Font(jComboBox1.g etSelected Item().toS tring(),jC omboBox2.g etSelected Item().toS tring(),In teger.pars eInt(jSpin ner1.getVa lue().toSt ring())));
}
I get the following error
"project_3.java": cannot resolve symbol: constructor Font (java.lang.String,java.lan g.String,i nt)in class java.awt.Font at line 347, column 24
My first combo box has the fonts name, 2nd combo box has the style (BOLD,PLAIN) ect, and the spinner acts as the size of the fonts.
When I run this everything works fine except the STYLE and I want to include that in the project
void jButton1_actionPerformed(A ctionEvent e) {
pageTA.setFont(new java.awt.Font(jComboBox1.g etSelected Item().toS tring(),ja va.awt.Fon t.PLAIN,In teger.pars eInt(jSpin ner1.getVa lue().toSt ring())));
}
Thank You Marcin
void jButton1_actionPerformed(A
pageTA.setFont(new java.awt.Font(jComboBox1.g
}
I get the following error
"project_3.java": cannot resolve symbol: constructor Font (java.lang.String,java.lan
My first combo box has the fonts name, 2nd combo box has the style (BOLD,PLAIN) ect, and the spinner acts as the size of the fonts.
When I run this everything works fine except the STYLE and I want to include that in the project
void jButton1_actionPerformed(A
pageTA.setFont(new java.awt.Font(jComboBox1.g
}
Thank You Marcin
The second parameter of the Font contructor is an integer primitive, but you pass in a String:
jComboBox2.getSelectedItem ().toStrin g()
You will have to convert your String to an integer first.
jComboBox2.getSelectedItem
You will have to convert your String to an integer first.
You can do it this way:
void jButton1_actionPerformed(A ctionEvent e) {
int style = Font.PLAIN;
String selectedStyle = jComboBox2.getSelectedItem ().toStrin g();
if (selectedStyle.equalsIgnor eCase("BOL D")) {
style = Font.BOLD;
} else if (selectedStyle.equalsIgnor eCase("ITA LIC")) {
style = Font.ITALIC;
}
pageTA.setFont(new java.awt.Font(jComboBox1.g etSelected Item().toS tring(), style,Integer.parseInt(jSp inner1.get Value().to String())) );
}
void jButton1_actionPerformed(A
int style = Font.PLAIN;
String selectedStyle = jComboBox2.getSelectedItem
if (selectedStyle.equalsIgnor
style = Font.BOLD;
} else if (selectedStyle.equalsIgnor
style = Font.ITALIC;
}
pageTA.setFont(new java.awt.Font(jComboBox1.g
}
ASKER
Thenx alot that worked !!!!!
youngsing
Do you know how to change the value on the jSpinner so i dosn't start at 0.
youngsing
Do you know how to change the value on the jSpinner so i dosn't start at 0.
>> I aslo have question about JSpinner .... How do you set the value for it so it dosen't start at 0 ... It will start at 10.
jSpinner1.getModel().setVa lue(new Integer(10));
jSpinner1.getModel().setVa
ASKER
I'm missing an identifier
jSpinner1.getModel().setVa lue(new Integer(10));
"project_3.java": <identifier> expected at line 46, column 21
Were the setValue is ???
jSpinner1.getModel().setVa
"project_3.java": <identifier> expected at line 46, column 21
Were the setValue is ???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great It works ... Thanx Alot for you help
You could store the following in the combobox:
new Integer(Font.BOLD),
new Integer(Font.PLAIN),
...
in that combo box instead of integers.
Then you could pass
((Integer)jComboBox2.getSe lectedItem ()).intVal ue()
as second parameter.
Of course then you need to define a simple ListCellRenderer for your combo box to display the right strings for the style.
Something like
public class StyleListCellRenderer extends JLabel implements ListCellRenderer {
public StyleStateListCellRenderer () {
setOpaque(true);
}
public java.awt.Component getListCellRendererCompone nt(javax.s wing.JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
if (value == null)
setText("?");
else {
switch ( ((Integer)value).intValue( ) ) {
case Font.BOLD :
setText("Bold");
break;
case Font.PLAIN :
setText("Plain");
break;
case default:
setText("?");
break;
}
}
setBackground(isSelected ?
list.getSelectionBackgroun d() : list.getBackground());
setForeground(isSelected ?
list.getSelectionForegroun d() : list.getForeground());
return this;
}
}
activate it by
ComboBox2.setRenderer(new StyleListCellRenderer());
For your spinner to start at 10:
mySpinner.setValue(new Integer(10));
Success
new Integer(Font.BOLD),
new Integer(Font.PLAIN),
...
in that combo box instead of integers.
Then you could pass
((Integer)jComboBox2.getSe
as second parameter.
Of course then you need to define a simple ListCellRenderer for your combo box to display the right strings for the style.
Something like
public class StyleListCellRenderer extends JLabel implements ListCellRenderer {
public StyleStateListCellRenderer
setOpaque(true);
}
public java.awt.Component getListCellRendererCompone
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
if (value == null)
setText("?");
else {
switch ( ((Integer)value).intValue(
case Font.BOLD :
setText("Bold");
break;
case Font.PLAIN :
setText("Plain");
break;
case default:
setText("?");
break;
}
}
setBackground(isSelected ?
list.getSelectionBackgroun
setForeground(isSelected ?
list.getSelectionForegroun
return this;
}
}
activate it by
ComboBox2.setRenderer(new StyleListCellRenderer());
For your spinner to start at 10:
mySpinner.setValue(new Integer(10));
Success
Sorry, too late.
ASKER
Thanx