aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Label in a field or scrollpanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Label in a field or scrollpanel" Watch "Label in a field or scrollpanel" New topic
Author

Label in a field or scrollpanel

matt prowell
Greenhorn

Joined: Jul 12, 2004
Posts: 18
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
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Label in a field or scrollpanel