Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Label in a field or scrollpanel

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is my code

import java.util.Vector;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Toolkit;
import java.io.*;

public class project extends JFrame implements ActionListener {


Vector partinfo = new Vector(0);
int figurenum = 0;
int imagenum = 0;

private JPanel mainPanel = new JPanel(),
figurePanel = new JPanel(),
partsPanel = new JPanel(),
mainPanel2 = new JPanel(),
verifyPanel = new JPanel(),
buttonPanel = new JPanel(),
buttonPanel2 = new JPanel();
//private ImagePanel figurePanel = new ImagePanel();
private JTextArea partslistfield = new JTextArea(20,35);
private JTextArea figurefield = new JTextArea(20,35);
private JTextArea verifyfield = new JTextArea(20,70);
private JButton verify = new JButton ("Verify ");
private JButton cancel = new JButton ("Cancel ");
private JButton back = new JButton ("Back ");
private JButton select = new JButton ("Select ");


public void start()
{
// String[] args;
String fileName = "c:/java/01i007.jpg";
checkFileAccessibility(fileName);
// if (args.length > 0);
// filename = args[0];

// Graphics g;
// Frame frame = new Frame();
ImageIcon icon = new ImageIcon(fileName);
checkLoadingStatus(icon);
JLabel label = new JLabel();
label.setIcon(icon);
//label.setSize(20,35);
figurefield.add(label);
pack();
setVisible(true);


mainPanel.remove(buttonPanel2);
mainPanel.remove(verifyPanel);
mainPanel.setBorder(BorderFactory.createTitledBorder("Parts"));
buttonPanel.add(verify);
buttonPanel.add(cancel);
figurePanel.setBorder(BorderFactory.createTitledBorder("Figure "));
figurePanel.add(figurefield);
figurePanel.add(new JScrollPane(figurefield));
partsPanel.setBorder(BorderFactory.createTitledBorder("Parts List"));
partsPanel.add(partslistfield);
partsPanel.add(new JScrollPane(partslistfield));
mainPanel.add(figurePanel);
mainPanel.add(partsPanel);
mainPanel.add(buttonPanel);
figurefield.add(label);
pack();
setVisible(true);
verify.addActionListener(this);
cancel.addActionListener(this);
getContentPane().add(mainPanel);
setSize(900,550);
setLocation(200, 100);
getContentPane().repaint();
//addWindowListener(new WindowAdapter( ) {
// public void windowClosing (WindowEvent e) { System.exit(0); }
// });

// Toolkit currentTK = Toolkit.getDefaultToolkit();
// Image figure = currentTK.getImage("01i007.cgm");

// drawImage(figure,0,0,this);
//getContentPane( ).add(
// new JScrollPane(figref(figure)));
//setVisible(true);
}


public void verify()
{
mainPanel.remove(buttonPanel);
mainPanel.remove(figurePanel);
mainPanel.remove(partsPanel);
mainPanel.setBorder(BorderFactory.createTitledBorder("Parts"));
buttonPanel2.add(back);
buttonPanel2.add(select);
verifyPanel.setBorder(BorderFactory.createTitledBorder("Parts List"));
verifyPanel.add(verifyfield);
verifyPanel.add(new JScrollPane(verifyfield));
mainPanel.add(verifyPanel);
mainPanel.add(buttonPanel2);
back.addActionListener(this);
select.addActionListener(this);
getContentPane().add(mainPanel);
getContentPane().repaint();
setSize(900,550);
setLocation(200, 100);
}

public project()
{
start();
}

public static void main(String arg[]) {
project back = new project();
back.setVisible(true);


} //init()
public void cleareverything()
{
verifyfield.setText( "");
figurefield.setText( "");
partslistfield.setText( "");
partinfo.clear();
}//cleareverything()


void checkFileAccessibility(String fileName) {
File file = new File(fileName);
System.out.println("file exists: " + file.exists());
System.out.println("file is readable: " + file.canRead());

} //checkFileAccessibilty

void checkLoadingStatus(ImageIcon icon) {
String status = "other";
switch (icon.getImageLoadStatus()) {
case MediaTracker.ABORTED:
status = "aborted";
break;
case MediaTracker.ERRORED:
status = "errored";
break;
case MediaTracker.COMPLETE:
status = "complete";
break;
}
System.out.println("image load status: " + status);
}//checkLoadingStatus



public void actionPerformed (ActionEvent evt)
{
//the if statement for if the cancel button is clicked
if (evt.getSource() == cancel){
cleareverything();
System.exit(0);
} //if cancel

if (evt.getSource() == verify){
verify();
} // if verify

if (evt.getSource() == back) {
start();
} // if back

if (evt.getSource() == select) {

} // if select

} //end actionPerformed
}//project

I want to have the label which contains a graphic to be in a scroll box next to the partlists field. How do I get the Image in there. Also is there anything to make it for you can zoom in and out on the graphic. Thanks
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
reply
    Bookmark Topic Watch Topic
  • New Topic