Results 1 to 6 of 6
Thread: JLabel + GUI problem
- 01-31-2009, 02:58 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 2
- Rep Power
- 0
JLabel + GUI problem
Hello
I have a JLabel2 which shows the spanish map. The thing is I do wanna draw lines on my spanish map and save it to as an image file in my desktop . I'm able to draw lines and save my JLabel2(spanish map) as an image in my Desktop. The problem is I'm not able to see any lines that I draw before in my image file. I can see those lines when I do click draw button but I can not see them when I save my file as an image to my desktop.Please help me.This problem killed me for two days..you can see how i converted to icon and how i save it as an image file below.Thank you for your helps from now.
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
File file3;
int returnVal = fc.showSaveDialog(routemap.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
try {
File f3 = fc.getSelectedFile();
ImageIcon icon = (ImageIcon) jLabel2.getIcon();
System.out.println(icon.getIconHeight());
BufferedImage buf = new BufferedImage(icon.getImage().getWidth(
null), icon.getImage().getHeight(null),
BufferedImage.TYPE_INT_RGB);
buf.getGraphics().drawImage(icon.getImage(), 0, 0,
icon.getIconWidth(), icon.getIconHeight(), null);
ImageIO.write(buf, "jpg", new File(f3.getAbsolutePath()
+ ".jpg"));
System.out.println(f3.getAbsolutePath());
} catch (IOException e) {
}
}
}
I have drawn lines by using draw function as you see below and I can not see those lines without any problem..Lines disapper in the image file when I do save it..Here is the draw button..
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
boolean go = true;
if (OneClicked == false && go == true) {
jLabel3.setText(jComboBox1.getSelectedItem() + " to ");
view = jComboBox1.getSelectedItem().toString() + " to ";
String m = jComboBox1.getSelectedItem().toString();
int size1 = City.size();
for (int i = 0; i < size1; i++) {
if (City.get(i).equals(m)) {
Index.add(i);
}
}
OneClicked = true;
go = false;
}
if (OneClicked == true && go == true) {
jLabel3.setText(view + jComboBox1.getSelectedItem());
view = "";
String m = jComboBox1.getSelectedItem().toString();
int size1 = City.size();
for (int i = 0; i < size1; i++) {
if (City.get(i).equals(m)) {
Index.add(i);
}
}
Graphics g = jLabel2.getGraphics();
g.setColor(Color.BLUE.darker());
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(3));
System.out.println(Index.size());
System.out.println(Index.size() - 2);
int m1 = Integer.parseInt(XCoordinate.get(Index
.get(Index.size() - 2)));
int n1 = Integer.parseInt(YCoordinate.get(Index
.get(Index.size() - 2)));
int m2 = Integer.parseInt(XCoordinate.get(Index
.get(Index.size() - 1)));
int n2 = Integer.parseInt(YCoordinate.get(Index
.get(Index.size() - 1)));
System.out.println(m1 + " " + n1 + " " + m2 + " " + n2);
g2.drawLine(m1, n1, m2, n2);
OneClicked = false;
}
System.out.println("index im" + Index);
}
-
Last edited by Fubarable; 01-31-2009 at 03:33 PM.
- 01-31-2009, 07:27 PM #3
And tested the slangword filter to breaking point on the Sun forum.
Definitely not a gentleman (nor lady)
db
- 02-01-2009, 07:58 PM #4
You're drawing on the JLabel, not the JLabel's icon. I suggest you get the BufferedImage behind the label first, and then draw onto that. Then you will both be able to display and save the BufferedImage.
- 02-02-2009, 12:59 PM #5
Member
- Join Date
- Jan 2009
- Posts
- 2
- Rep Power
- 0
It's still same OrangeDog :(.
- 02-03-2009, 01:46 AM #6
Similar Threads
-
jLabel
By Matty in forum AWT / SwingReplies: 3Last Post: 09-22-2008, 10:22 PM -
GUI - JLabel
By Azndaddy in forum New To JavaReplies: 8Last Post: 05-02-2008, 07:03 AM -
help me with JFrame and JLabel
By michcio in forum New To JavaReplies: 5Last Post: 11-20-2007, 07:44 AM -
JLabel
By Jack in forum AWT / SwingReplies: 2Last Post: 07-02-2007, 01:55 PM -
JLabel
By Freddie in forum AWT / SwingReplies: 2Last Post: 05-29-2007, 02:19 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks