Conversion from awt to Swing, colored list widget, and awt update() method

Now that my Interactive Color Wheel program/applet is in Swing, I guess I should continue my previous thread in here from the AWT forum ("list widget with different colors for each list item?"):
* list widget with different colors for each list item?
My current issue involves two canvas (well, JPanel) refresh issues likely linked to double buffering. You can see them by running the following file with "java -jar SIHwheel.jar":
* http://r0k.us/rock/Junk/SIHwheel.jar
[edit add]
(Heh, I just noticed Firefox and Chrome under Windows 7 will allow you to run thie .jar directly from the link. Cool.)
[edit]
If you don't trust me and would rather run it as an applet, use:
* http://r0k.us/rock/Junk/SIHwheel.html
(For some reason the first issue doesn't manifest when running as applet.)
1) The canvas goes "wonky-white" when the user first clicks on the wheel. What is supposed to happen is simply the user sees another dot on the wheel for his new selected color. Forcing a complete redraw via any of the GUI buttons at the bottom sets things right. The canvas behaves itself from then on, at least until minimized or resized, at which point one needs to click a GUI button again. I'll be disabling resizing, but minimizing will still be allowed.
2) A button image, and sometimes toolTip text, from an entirely different JPanel will appear in the ULC (0,0) of my canvas.
Upon first running the new Swing version, I had thought everything was perfect. I soon realized though that my old AWT update() method was never getting called. The desired case when the user clicks somewhere on the wheel is that a new dot appears on his selected color. This usually allows them to see what colors have been viewed before. The old paint(), and now paintComponent(), clear the canvas, erasing all the previous dots.
I soon learned that Swing does not call update(). I had been using it to intercept refresh events where only one of the components on my canvas needing updating. Most usefully, don't redraw the wheel (and forget the dots) when you don't need to. The way I chose to handle this is to slightly modify the update() to a boolean method. I renamed it partialOnly() and call it
at the beginning of paintComponent(). If it returns true, paintComponent() itself returns, and no clearing of the canvas occurs.
Since I first posted about these two issues, I've kludged-in a fix to #1. (The linked .jar file does not contain this kludge, so you can see the issue.) The kludge is included in the following code snippet:
    public void paintComponent(Graphics g)
        Rectangle ulc;
     if (font == null)  defineFont(g);
     // handle partial repaints of specific items
     if (partialOnly(g))  return;
        ...  // follow with the normal, full-canvas refresh
    private boolean partialOnly(Graphics g)
     boolean     imDone = true;
     if (resized > 0)  // this "if { }" clause is my kludge
     {   // should enter on 1 or 2
         imDone = false;
         resized += 1;     // clock thru two forced-full paints
         if (resized > 2)  resized = 0;
        if (wedgeOnly)
         putDotOnWheel(g);
            paintWedge(g);
         drawSnake(g);
         drawSatSnake(g);
         updateLumaBars(g);
            wedgeOnly = false;
          else if (wheelOnly)
            wheelOnly = false;
          else
            imDone = false;  // was paint() when method was update() in the AWT version
        return(imDone);
    }Forcing two initial full paintComponent()s does whatever magic the double-buffering infrastructure needs to avoid the "wonky-white" problem. This also happens on a minimize; I've disabled resizing other than minimization. Even though it works, I consider it a kludge.
The second issue is not solved. All I can figure is that the double buffers are shared between the two JPanels, and the artifact buttons and toolTips at (0,0) are the result. I tried simply clearing the top twenty lines of the canvas when partialOnly() returns true, but for some reason that causes other canvas artifacting further down. And that was just a second kludge anyway.
Sorry for being so long-winded. What is the right way to avoid these problems?
-- Rich
Edited by: RichF on Oct 15, 2010 8:43 PM

Darryl, I'm not doing any custom double buffering. My goal was to simply replicate the functionality of awt's update() method. And yes, I have started with the Swing tutorial. I believe it was there that I learned update() is not part of the Swing infrastructure.
Problem 1: I don't see the effect you describe (or I just don't understand the description)Piet, were you viewing the program (via the .jar) or the applet (via the .html)? For whatever reason, problem 1 does not manifest itself as an applet, only a program. FTR I'm running JDK/JRE 1.6 under Windows 7. As a program, just click anywhere in the wheel. The whole canvas goes wonky-white, and the wheel doesn't even show. If it happens, you'll understand. ;)
Are you aware that repaint() can have a rectangle argument? And are you aware that the Graphics object has a clip depicting the area that will be affected by painting? You might use these for your partial painting.Yes and yes. Here is an enumeration of most of the update regions:
enum AoI    // areas of interest
    LUMA_SNAKE, GREY_SNAKE, HUEBORHOOD, BULB_LABEL, LUMA_WEDGE,
    LAST_COLOR, BRIGHTNESS_BOX, INFO_BOX, VERSION,
    COLOR_NAME, EXACT_COLOR, LUMA_BUTTON, LUMA_BARS, GUI_INTENSITY,
    QUANTIZATION_ERROR
}That list doesn't even include the large color intensity wedge to the right, nor the color wheel itself. I have a method that will return a Rectangle for any of the AoI's. One problem is that the wheel is a circle, and a containing rectangle will overlap with some of the other AoI's. I could build an infrastructure to handle this mess one clip region at a time, but I think it would add a lot of unnecessary complexity.
I think the bigger picture is that, though it is now updated to Swing, some of the original 1998 design decisions are no longer relevant. Back then I was running Windows 98 on a single-core processor clocked at significantly less than 1 GHz. You could actually watch the canvas update itself. The color wheel alone fills over 1000 arcs, and the color intensity wedge has over 75 update regions of its own. While kind of interesting to watch, it's not 1998 any more. My multi-core processor runs at over 2 GHz, and my graphic card is way, way beyond anything that existed last century. Full canvas updates probably take less than 0.1 sec, and that is with double-buffering!
So, I think you're right. Let the silly paintComponent() do it's thing unhindered. If I want to track old dots on the wheel, keep an array of Points, remembering maybe the last 10. As a final step in the repainting process, decide how many of those old dots to display, and do it.
Thanks, guys, for being a sounding board.
Oh, I'm moving forward on implementing the color list widget. I've already added a 3rd JPanel, which is a column to the left of the main paint canvas. It will contain 3 GUI items:
1) the color list widget itself, initially sorted by name
2) 3 radio buttons allowing user to resort the list by name, hue, or hex
3) a hex-entry JTextField (which is all that is there at this very moment), allowing exact color request
The color list widget will fill most of the column from the top, followed by the radio buttons, with hex-entry at bottom.
For weeks I had in mind that I wanted a pop-up color list widget. Then you shared your ColorList class, and it was so obvious the list should just be there all the time. :)
-- Rich

Similar Messages

  • Has anyone else gotten an email supposedly from Apple saying you had missing data and to update? I went to update, gave some info only to see they wanted my credit card info and money. How do I report this and to whom. Impossible to contact Apple.

    Has anyone gotten an email saying your system was missing data and to update? I went to update, gave my email and password just to find it wasn't really Apple
    but, wanted my credit card and money. Did not follow up. Where and how do I report this to Apple. Seems impossible to contact them.

    Forward it to [email protected] and then delete it.
    (112838)

  • Sync old iMessage conversations from iPhone to new iPad & Mac?

    I have had my iPhone for a couple years now, and have accumulated a fairly large amount of iMessage conversations from various people. A few days ago, I purchased my first iPad and also updated my Mac to Mountain Lion. By doing so, I now have access to iMessage on three devices in total, whereas before I only had one.
    I have managed to setup my devices so that all new iMessages I send and receive are being synced between them. However, is it possible to sync my old iMessage conversations from my iPhone back onto my iPad and Mac?
    I would like to do so in order to keep a full record of the past conversations I have had with my contacts.
    I have done a bit of research before posting, but the only related topics I found werehttps://discussions.apple.com/message/19095937 andhttps://discussions.apple.com/message/17818920. The former was left unresolved, whereas the latter describes a solution which I am unable to reproduce.
    Could anyone shed some light on this for me?

    Hi,
    For me this was very early on in my Mountain Lion days.
    I would now say that you cannot sync iMessages from an iOS device that were sent before your linked any Apple ID with the iPhone Number or added the Mac to the use of the Apple ID.
    At the point at which and Apple ID is used on both an iPad and the Mac version of Messages becomes it's "Start date"
    The same can be said for adding an Apple ID to an iPhone and the Mac.
    On the Mac all messages can be saved if you wish.
    This are in the .ichat format which you can send to Mac  Buddies and then can open them and read them as if they were the chat (i.e they display as "chats').
    There appears to be no way in iTunes to access the iMessages (or SMS ones) on the iPhone.
    Someone who knows more about the iOS may be able to tell you if they are accessible another way.
    8:52 PM      Friday; May 24, 2013
      iMac 2.5Ghz 5i 2011 (Mountain Lion 10.8.3)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • Restore an iMessage conversation from Mac to iPhone

    Hi,
    A couple of months ago, I deleted a contact from my address book, along with the corresponding iMessage conversation from this contact.  Both the contact and the conversation were manually deleted from my Mac and my iPhone (I think, although maybe I just deleted it from my iPhone?).  Both devices are using the same AppleID/iCloud account.
    About a month ago, I added the contact back in (I can't recall if I added the contact back on my Mac first or my iPhone first) and the entire iMessage conversation had been restored on my Mac (I was actually quite amazed that the entire conversation was restored on the Mac.  I didn't really know that all that is stored in lCloud).  On my iPhone, however, only the iMessage conversation messages that were exchanged since the contact was added back in are present on the iPhone.
    Is there a way to force the iPhone to refresh the entire conversation from this particular contact from iCloud, or from my Mac?
    I use iCloud backup to back up my phone, not my Mac.
    Thanks!
    MacBook Pro with Retina display, OS X Yosemite (10.10), 15" Mid 2014 i7 2.8 16GB 1TB
    iPhone 6 Plus, iOS 8.1

    Not that I know of. You would have to restore a back-up of the iPhone before the message was deleted. You can also take screen shots on the Mac of the conversation. That would save the conversation in your photos, and you can sync those. Maybe someone else can chime in if I'm missing something.

  • Source list supplier and latest Infor Record price

    Hi,
    Which SAP code can use to run the report to list display for parts current source list supplier and most update info record price?
    Thanks
    Asini Yadaiah....

    Hi,
    Run following reports;
    ME0M - Source List per Material
    ME1M - Info Record per Material
    ME1L - Info Record per Vendor
    ME1P - PO Price History

  • Help Plz! AWT to Swing Conversion

    Hey everyone, I'm new to java and trying to convert this AWT program to Swing, I got no errors, the menu shows but they dont work !! Could somebody please help me? thanks alot!
    Current Under-Construction Code: (no errors)
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class zipaint extends JFrame implements ActionListener,      ItemListener,
    MouseListener, MouseMotionListener, WindowListener {
    static final int WIDTH = 800;     // Sketch pad width
    static final int HEIGHT = 600;     // Sketch pad height
    int upperLeftX, upperLeftY;     // Rectangle upper left corner coords.
    int width, height;          // Rectangle size
    int x1, y1, x2, y2, x3, y3, x4, y4; // Point coords.
    boolean fillFlag = false; //default filling option is empty
    boolean eraseFlag = false; //default rubber is off
    String drawColor = new String("black"); //default drawing colour is black
    String drawShape = new String("brush"); //default drawing option is brush
    Image background; //declear image for open option
    private FileDialog selectFile = new FileDialog( this,
    "Select background (.gif .jpg)",
    FileDialog.LOAD );
    // Help
    String helpText = "Draw allows you to sketch different plane shapes over a " +
    "predefined area.\n" + "A shape may be eother filled or in outline, " +
    "and in one of eight different colours.\n\n" + "The position of the " +
    "mouse on the screen is recorded in the bottom left-hand corner of the " +
    "drawing area. The choice of colour and shape are disoplayed also in the " +
    "left-habnd corner of the drawing area.\n\n" + "The size of a shape is " +
    "determined by the mouse being dragged to the final position and " +
    "released. The first click of the mouse will generate a reference dot on " +
    "the screen. This dot will disapear after the mouse button is released.\n\n" +
    "Both the square and the circle only use the distance measured along the " +
    "horizontal axis when determining the size of a shape.\n\n" + "Upon " +
    "selecting erase, press the mouse button, and move the mouse over the " +
    "area to be erased. releasing the mouse button will deactivate erasure.\n\n" +
    "To erase this text area choose clearpad from the TOOLS menu.\n\n";
    // Components
    JTextField color = new JTextField();
    JTextField shape = new JTextField();
    JTextField position = new JTextField();
    CheckboxGroup fillOutline = new CheckboxGroup();
    JTextArea info = new JTextArea(helpText,0,0/*,JTextArea.JSCROLLBARS_VERTICAL_ONLY*/);
    JFrame about = new JFrame("About Zi Paint Shop");
    // Menues
    String[] fileNames = {"Open","Save","Save as","Exit"};
    String[] colorNames = {"black","blue","cyan","gray","green","magenta","red","white","yellow"};
    String[] shapeNames = {"brush","line","square","rectangle","circle","ellipse"};
    String[] toolNames = {"erase","clearpad"};
    String[] helpNames = {"Help","about"};
    public zipaint(String heading) {
    super(heading);
    getContentPane().setBackground(Color.white);
    getContentPane().setLayout(null);
    /* Initialise components */
    initialiseTextFields();
    initializeMenuComponents();
    initializeRadioButtons();
    addWindowListener(this);
    addMouseListener(this);
    addMouseMotionListener(this);
    /* Initialise Text Fields */
    private void initialiseTextFields() {
    // Add text field to show colour of figure
    color.setLocation(5,490);
    color.setSize(80,30);
    color.setBackground(Color.white);
    color.setText(drawColor);
    getContentPane().add(color);
    // Add text field to show shape of figure
    shape.setLocation(5,525);
    shape.setSize(80,30);
    shape.setBackground(Color.white);
    shape.setText(drawShape);
    getContentPane().add(shape);
    // Add text field to show position of mouse
    position.setLocation(5,560);
    position.setSize(80,30);
    position.setBackground(Color.white);
    getContentPane().add(position);
    // Set up text field for help
    info.setLocation(150,250);
    info.setSize(500,100);
    info.setBackground(Color.white);
    info.setEditable(false);
    private void initializeMenuComponents() {
    // Create menu bar
    JMenuBar bar = new JMenuBar();
    // Add colurs menu
    JMenu files = new JMenu("Files");
    for(int index=0;index < fileNames.length;index++)
    files.add(fileNames[index]);
    bar.add(files);
    files.addActionListener(this);
    // Add colurs menu
    JMenu colors = new JMenu("COLORS");
    for(int index=0;index < colorNames.length;index++)
    colors.add(colorNames[index]);
    bar.add(colors);
    colors.addActionListener(this);
    // Add shapes menu
    JMenu shapes = new JMenu("SHAPES");
    for(int index=0;index < shapeNames.length;index++)
    shapes.add(shapeNames[index]);
    bar.add(shapes);
    shapes.addActionListener(this);
    // Add tools menu
    JMenu tools = new JMenu("TOOLS");
    for(int index=0;index < toolNames.length;index++)
    tools.add(toolNames[index]);
    bar.add(tools);
    tools.addActionListener(this);
    // Add help menu
    JMenu help = new JMenu("HELP");
    for(int index=0;index < helpNames.length;index++)
    help.add(helpNames[index]);
    bar.add(help);
    help.addActionListener(this);
    // Set up menu bar
    setJMenuBar(bar);
    /* Initilalise Radio Buttons */
    private void initializeRadioButtons() {
    // Define checkbox
    Checkbox fill = new Checkbox("fill",fillOutline,false);
    Checkbox outline = new Checkbox("outline",fillOutline,true);
    // Fill buttom
    fill.setLocation(5,455);
    fill.setSize(80,30);
    getContentPane().add(fill);
    fill.addItemListener(this);
    // Outline button
    outline.setLocation(5,420);
    outline.setSize(80,30);
    getContentPane().add(outline);
    outline.addItemListener(this);
    /* Action performed. Detects which item has been selected from a menu */
    public void actionPerformed(ActionEvent e) {
    Graphics g = getGraphics();
    String source = e.getActionCommand();
    // Identify chosen colour if any
    for (int index=0;index < colorNames.length;index++) {
    if (source.equals(colorNames[index])) {
    drawColor = colorNames[index];
    color.setText(drawColor);
    return;
    // Identify chosen shape if any
    for (int index=0;index < shapeNames.length;index++) {
    if (source.equals(shapeNames[index])) {
    drawShape = shapeNames[index];
    shape.setText(drawShape);
    return;
    // Identify chosen tools if any
    if (source.equals("erase")) {
    eraseFlag= true;
    return;
    else {
    if (source.equals("clearpad")) {
    remove(info);
    g.clearRect(0,0,800,600);
    return;
    if (source.equals("Open")) {
    selectFile.setVisible( true );
    if( selectFile.getFile() != null )
    String fileLocation = selectFile.getDirectory() + selectFile.getFile();
    background = Toolkit.getDefaultToolkit().getImage(fileLocation);
    paint(getGraphics());
    if (source.equals("Exit")) {
    System.exit( 0 );
    // Identify chosen help
    if (source.equals("Help")) {
    getContentPane().add(info);
    return;
    if (source.equals("about")) {
    displayAboutWindow(about);
    return;
    public void paint(Graphics g)
    super.paint(g);
    if(background != null)
    Graphics gc = getGraphics();
    gc.drawImage( background, 0, 0, this.getWidth(), this.getHeight(), this);
    /* Dispaly About Window: Shows iformation aboutb Draw programme in
    separate window */
    private void displayAboutWindow(JFrame about) {
    about.setLocation(300,300);
    about.setSize(350,160);
    about.setBackground(Color.cyan);
    about.setFont(new Font("Serif",Font.ITALIC,14));
    about.setLayout(new FlowLayout(FlowLayout.LEFT));
    about.add(new Label("Author: Zi Feng Yao"));
    about.add(new Label("Title: Zi Paint Shop"));
    about.add(new Label("Version: 1.0"));
    about.setVisible(true);
    about.addWindowListener(this);
    // ----------------------- ITEM LISTENERS -------------------
    /* Item state changed: detect radio button presses. */
    public void itemStateChanged(ItemEvent event) {
    if (event.getItem() == "fill") fillFlag=true;
    else if (event.getItem() == "outline") fillFlag=false;
    // ---------------------- MOUSE LISTENERS -------------------
    /* Blank mouse listener methods */
    public void mouseClicked(MouseEvent event) {}
    public void mouseEntered(MouseEvent event) {}
    public void mouseExited(MouseEvent event) {}
    /* Mouse pressed: Get start coordinates */
    public void mousePressed(MouseEvent event) {
    // Cannot draw if erase flag switched on.
    if (eraseFlag) return;
    // Else set parameters to 0 and proceed
    upperLeftX=0;
    upperLeftY=0;
    width=0;
    height=0;
    x1=event.getX();
    y1=event.getY();
    x3=event.getX();
    y3=event.getY();
    Graphics g = getGraphics();
    displayMouseCoordinates(x1,y1);
    public void mouseReleased(MouseEvent event) {
    Graphics g = getGraphics();
    // Get and display mouse coordinates
    x2=event.getX();
    y2=event.getY();
    displayMouseCoordinates(x2,y2);
    // If erase flag set to true reset to false
    if (eraseFlag) {
    eraseFlag = false;
    return;
    // Else draw shape
    selectColor(g);
    if (drawShape.equals("line")) g.drawLine(x1,y1,x2,y2);
    else if (drawShape.equals("brush"));
    else drawClosedShape(drawShape,g);
    /* Display Mouse Coordinates */
    private void displayMouseCoordinates(int x, int y) {
    position.setText("[" + String.valueOf(x) + "," + String.valueOf(y) + "]");
    /* Select colour */
    private void selectColor(Graphics g) {
    for (int index=0;index < colorNames.length;index++) {
    if (drawColor.equals(colorNames[index])) {
    switch(index) {
    case 0: g.setColor(Color.black);break;
    case 1: g.setColor(Color.blue);break;
    case 2: g.setColor(Color.cyan);break;
    case 3: g.setColor(Color.gray);break;
    case 4: g.setColor(Color.green);break;
    case 5: g.setColor(Color.magenta);break;
    case 6: g.setColor(Color.red);break;
    case 7: g.setColor(Color.white);break;
    default: g.setColor(Color.yellow);
    /* Draw closed shape */
    private void drawClosedShape(String shape,Graphics g) {
    // Calculate correct parameters for shape
    upperLeftX = Math.min(x1,x2);
    upperLeftY = Math.min(y1,y2);
    width = Math.abs(x1-x2);
    height = Math.abs(y1-y2);
    // Draw appropriate shape
    if (shape.equals("square")) {
    if (fillFlag) g.fillRect(upperLeftX,upperLeftY,width,width);
    else g.drawRect(upperLeftX,upperLeftY,width,width);
    else {
    if (shape.equals("rectangle")) {
    if (fillFlag) g.fillRect(upperLeftX,upperLeftY,width,height);
    else g.drawRect(upperLeftX,upperLeftY,width,height);
    else {
    if (shape.equals("circle")) {
    if (fillFlag) g.fillOval(upperLeftX,upperLeftY,width,width);
    else g.drawOval(upperLeftX,upperLeftY,width,width);
    else {
    if (fillFlag) g.fillOval(upperLeftX,upperLeftY,width,height);
    else g.drawOval(upperLeftX,upperLeftY,width,height);
    /* Mouse moved */
    public void mouseMoved(MouseEvent event) {
    displayMouseCoordinates(event.getX(),event.getY());
    /* Mouse dragged */
    public void mouseDragged(MouseEvent event) {
    Graphics g = getGraphics();
    x2=event.getX();
    y2=event.getY();
    x4=event.getX();
    y4=event.getY();
    displayMouseCoordinates(x1,y1);
    if (eraseFlag) g.clearRect(x2,y2,10,10);
    else {
    selectColor(g);
    if(drawShape.equals("brush")) g.drawLine(x3,y3,x4,y4);
    x3 = x4;
    y3 = y4;
    // ---------------------- WINDOW LISTENERS -------------------
    /* Blank methods for window listener */
    public void windowClosed(WindowEvent event) {}
    public void windowDeiconified(WindowEvent event) {}
    public void windowIconified(WindowEvent event) {}
    public void windowActivated(WindowEvent event) {}
    public void windowDeactivated(WindowEvent event) {}
    public void windowOpened(WindowEvent event) {}
    /* Window Closing */
    public void windowClosing(WindowEvent event) {
    if (event.getWindow() == about) {
    about.dispose();
    return;
    else System.exit(0);
    Code End
    Thanks again!
    class ziapp {
    /* Main method */
    public static void main(String[] args) {
    zipaint screen = new zipaint("Zi Paint Shop");
    screen.setSize(zipaint.WIDTH,zipaint.HEIGHT);
    screen.setVisible(true);

    First of all use the [url http://forum.java.sun.com/features.jsp#Formatting]Formatting Tags when posting code to the forum. I'm sure you don't code with every line left justified so we don't want to read unformatted code either.
    Hey everyone, I'm new to java and trying to convert this AWT program to SwingInstead of converting the whole program, start with something small, understand how it works and then convert a different part of the program. You can start by reading this section from the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html]How to Use Menus.
    From a quick glance of your code it looks like you are not adding an ActionListener to your JMenuItems. You are adding them to the JMenu.
    Other observations:
    1) Don't mix AWT with Swing components. You are still using CheckBox
    2) Don't override paint(). When using Swing you should override paintComponent();
    3) Use LayoutManagers. Using a null layout does not allow for easy maintenance of the gui. Right now you are using 800 x 600 as your screen size. Most people are probably using at least 1024 x 768 screen sizes. When using LayoutManagers you would suggest component sizes by using setPreferredSize(), not setSize().

  • Changing scrollbar color on list widget.

    Good Afternoon,
    I need to know if its possible to change the scrollbar color of the list widget. If so, where can I find information covering this.
    Thank you.

    Repost.

  • Invoke an awt event from outside the swing application

    Is it possible to invoke an awt event triggered from outside the swing app? I am trying to implement a use case where i have to open a new tab in an already running swing app when a user clicks on a browser link.

    I have a desktop application that was invoked via webstart. The java webstart process started when the user clicked on a link that downloaded the swing application and now it runs in the clients JVM. Each browser click downloades and launches the application that performs a certain function. Now lets say, the user clicks on another link, then i don't want another java application to be launched. I want the same application that executes the function in lets say a new tab.
    Its kind of like you click on a link that somebody sent you in an outlook email. When you click on it and if firefox is already running, the link opens up in a new tab on an already running firefox browser. If firefox was not running, it starts a new firefox process.
    Hope this makes sense

  • From awt to swing = classcastexception ?

    Hi !
    I am trying to move from awt to swing (j2sdk1.4.0_01)
    On recompiling with javac, no visible errors, nor when I try to debug with jdb.
    However when I try to load the class file, the java console tells me that I have a ClassCastException. Going thru the codes, I cannot see where I have type-casted anything wrong !
    Can someone point me in the right direction ?
    THX

    Hi !
    Tried some very simple codes...
    import javax.swing.*;
    public class TreeExample
    public static void main(String args[])
    JFrame frame = new JFrame("The Tree");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(250,250);
    frame.show();
    jdb will run it and display it in an appletviewer
    window, but IE and Netscape will report a
    ClassCastException...
    At this point I think it might be some plug-ins ?The example you gave isn't an applet. Were you trying to run this exact code in a browser or was this just a sample? If you are trying to run this in a browser, it's probably trying to cast your TreeExample class to an Applet, which would explain the ClassCastException.

  • AWT to SWING conversion - i am so lost!!!

    Hi,
    i am hoping somebody's expertise can help me. i am still relatively new to java and have created this class in java which has an AWT gui, that enables a user to click a "load" button, which the user can then select the jpeg they want to load and the class loads the picture in the canvas. Once i had created it i realised that i actually need to do it in SWING, but the problem is that i dont know how to convert this AWT class to a SWING based class. I have included the code below, and would really appreciate it if somebody can show me how to convert my code so that it is in SWING instead.
    Thank you for your help.
    kind regards,
    Very Confused One
    --------------------------START OF CODE [ImageDicer.java] --------------------------
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.util.*;
    public class ImageDicer extends Frame
    public static void main(String[] args)
    String fileName = "default";
    if (args.length > 0) fileName = args[0];
    new ImageDicer(fileName);
    private static final String kBanner = "ImageDicer v1.0";
    public ImageDicer(String fileName)
    super(kBanner);
    createUI();
    loadImage(fileName);
    setVisible(true);
    private Panel mControlPanel;
    private void createUI()
    setFont(new Font("Serif", Font.PLAIN, 12));
    setLayout(new BorderLayout());
    final Label statusLabel = new Label("Welcome to " + kBanner + ".");
    Button loadButton = new Button("Load...");
    loadButton.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    FileDialog fd = new FileDialog(ImageDicer.this);
    fd.show();
    if (fd.getFile() == null) return;
    String path = fd.getDirectory() + fd.getFile();
    loadImage(path);
    mControlPanel = new Panel();
    mControlPanel.add(loadButton);
    mControlPanel.add(statusLabel);
    add(mControlPanel, BorderLayout.SOUTH);
    addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e)
    dispose();
    System.exit(0);
    private void adjustToImageSize()
    if (!isDisplayable()) addNotify(); // Do this to get valid Insets.
    Insets insets = getInsets();
    int w = mBufferedImage.getWidth() + insets.left + insets.right;
    int h = mBufferedImage.getHeight() + insets.top + insets.bottom;
    h += mControlPanel.getPreferredSize().height;
    setSize(w, h);
    private void center()
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension d = getSize();
    int x = (screen.width - d.width) / 2;
    int y = (screen.height - d.height) / 2;
    setLocation(x, y);
    private BufferedImage mBufferedImage;
    private void loadImage(String fileName)
    Image image = Toolkit.getDefaultToolkit().getImage(fileName);
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 0);
    try { mt.waitForID(0); }
    catch (InterruptedException ie) { return; }
    if (mt.isErrorID(0)) return;
    mBufferedImage = new BufferedImage(image.getWidth(null),
    image.getHeight(null),
    BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = mBufferedImage.createGraphics();
    g2.drawImage(image, null, null);
    adjustToImageSize();
    center();
    validate();
    repaint();
    setTitle(kBanner + ": " + fileName);
    public void paint(Graphics g)
    if (mBufferedImage == null) return;
    Insets insets = getInsets();
    g.drawImage(mBufferedImage, insets.left, insets.top, null);
    --------------------------END OF CODE [ImageDicer.java] --------------------------

    Thanks again for your assistance. The class manages to compile now but there seems to be a bug in the program. Everytime i run the class, the window loads, but the load button does not appear. It only appears when you click aimlessly at the bottom of the window until u luckily click on it. i cannot understand why this is happening :s
    Again i am greatful for your help.
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import java.util.*;
    import javax.imageio.ImageIO;
    import java.net.*;
    import javax.swing.filechooser.*;
    public class ImageDicer extends JFrame
    String kBanner = "ImageDicer v1.0";
    JPanel mControlPanel;
    JLabel statusLabel;
    JButton loadButton;
    public BufferedImage mBufferedImage;
    public ImageDicer(String fileName)
    { Container pane=getContentPane();
         setTitle(kBanner);
         pane.setLayout(new BorderLayout());
    statusLabel = new JLabel("Welcome to " + kBanner + ".");
    loadButton = new JButton("Load...");
    loadButton.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    {  JFileChooser fd = new JFileChooser();
         int returnVal=fd.showOpenDialog(ImageDicer.this);
              if(returnVal==JFileChooser.APPROVE_OPTION)
                   {if (fd.getSelectedFile() == null)
                              {return;}
                                  File file=fd.getSelectedFile();
                                  String path=(String)file.getPath();
                                  loadImage(path);
    mControlPanel = new JPanel();
         mControlPanel.add(loadButton);
         mControlPanel.add(statusLabel);
    pane.add( BorderLayout.SOUTH, mControlPanel);
    public void adjustToImageSize()
    if (!isDisplayable()) addNotify(); // Do this to get valid Insets.
    Insets insets = getInsets();
    int w = mBufferedImage.getWidth() + insets.left + insets.right;
    int h = mBufferedImage.getHeight() + insets.top + insets.bottom;
    h += mControlPanel.getPreferredSize().height;
    setSize(w, h);
    public void center()
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension d = getSize();
    int x = (screen.width - d.width) / 2;
    int y = (screen.height - d.height) / 2;
    setLocation(x, y);
    public void loadImage(String fileName)
    Image image = Toolkit.getDefaultToolkit().getImage(fileName);
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 0);
    try { mt.waitForID(0); }
    catch (InterruptedException ie) { return; }
    if (mt.isErrorID(0)) return;
    mBufferedImage = new BufferedImage(image.getWidth(null),
    image.getHeight(null),
    BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = mBufferedImage.createGraphics();
    g2.drawImage(image, null, null);
    adjustToImageSize();
    center();
    validate();
    repaint();
    setTitle(kBanner + ": " + fileName);
    public void paint(Graphics g)
    if (mBufferedImage == null) return;
    Insets insets = getInsets();
    g.drawImage(mBufferedImage, insets.left, insets.top, null);
    public static void main(String[] args)
    String fileName = "default";
    if (args.length > 0) fileName = args[0];
    ImageDicer img=new ImageDicer(fileName);
    img.setSize(800,600);
    img.show();
    }

  • How can I create a my own dialog in awt or swings

    How can I create a my own dialog in awt or swings instead of JDialog,Joption.
    if possible some example.
    Thanks in advance
    bhaskar

    hi,
    just use the building blocks of of GUI components and their methods. For examlpe u want to write a Font Dialog box,
    use Frame with lists , thers is classes by which u can pick the all fonts installes on ur system. Do appropriate programming to event handlers . On last in event handler of 'OK' button get the selected item from list and assign to wht u want thats all...........

  • Can I build a GUI application with SWING only without [import java.awt.*;]

    I have seen several threads (in forums), books and tutorials about SWING and I see that they all mix SWING with AWT (I mean they import both Swing and AWT in their code).
    The conclusion that comes out is:
    It is good to learn about SWING and forget AWT as it won't be supported later. I have decided to do so, and I never include <<import java.awt.*;>> in my code.
    But I see that you cannot do much without <<import java.awt.*;>>. For example this line which changes the background color:
    <<frame.getContentPane().setBackground(Color.red)>>
    works only with <<import java.awt.*;>>. I have seen that codes in this and other forums import awt to change the background. Why is that?
    After all, I wonder, what can I do;
    My question is, can I change the background (and of course do all other things listener, buttons etc) without using <<import java.awt.*;>>.
    I would like to avoid using <<import java.awt.*;>> and using awt since my program will not work later.
    In addition, I believe there is no point to learn awt, which later will not exist.
    I know, I must have misunderstood something. I would appreceate it very much, if anyone could give me even a short answer.
    Thank you in advance,
    JMelsi

    Since swing is a layer on top of awt, AWT will exist for as long as swing does.
    If sun does ever remove AWT they will have to replace it something else swing can layer on to and you will probably only have to replace your import statements.
    The main difference is the way there drawn to the screen.
    You can do custom drawing on swing components but you can't on AWT.
    If your using a desktop PC system it's probably best to use swing just in case you wish to do some custom drawing.
    awt uses less memory than swing and is faster but swing can be extended. awt comes only as standard.
    Say for example you wish to implement a JButton with a ProgressBar below the button text, this can be done with swing!

  • How can I print a text message conversation from my iPhone? Not using screenshots.

    How can I print a text message conversation from my iPhone? Not using screenshots. It's around 500 messages so screenshots is not a option.

    Yes, you can delete from iphone:
    http://manuals.info.apple.com/enUS/iPhone_iOS4_UserGuide.pdf
    It is covered in the manual.
    Page 172:
    "Delete a podcast: In the Podcasts list in iPod, swipe left or right over the podcast, then
    tap Delete. "

  • How do I change an hp officejet j6400 printer change from color to black and white?  I have a Mac 10.8 OX system

    How do I change an hp officejet j6400 printer change from color to black and white?
    I have a Mac 10.8 OX system

    Hi JasperNM,
    You may access a card within the cart reader by mapping a network drive to access it, then you may transfer the fies to your Mac.
    First locate the printer IP address as following:
    Follow these steps to print a Wireless Network Test Report, the IP address will be listed within that report:
    On the control panel, press the Setup button ( ).
    Press the Right Arrow button ( ) to scroll to Network Setup , and then press the OK button.
    Press the OK button to select Print Network Settings .
    Press the Right Arrow button ( ) to scroll to Wireless Test Report , and then press the OK button. The Wireless Network Test Report prints.
    Now map a network driver by following the steps below:
    Click the Finder icon on your Mac.
    Click the Go menu.
    Click on Connect to Server.
    In the Server Address field enter “smb://ipaddress of the printer” and click on Connect.
    You will be prompted to enter the password. leave it as is and click on Connect.
    The Memory card will be mounted as a disk in the Finder.
    Shlomi

  • Conversion from BO 5.1.9 Deski to BO XI 3.1 SP3 Webi

    Hi Everyone,
    As part of of our project, we are executing a BO upgrade project and have undertaken BO report migration and conversion from deskI in BO 5.1.9 to WebI in BO XI 3.1. The conversion of reports was assumed to be carried out through the report conversion tool (RCT) of BO XI 3.1 SP3. However, RCT has failed in converting all deskI reports to WebI.
    Hence, we are seeking your help & assistance in finding out, the optimal way of resolving the problem. Can you please indicate:
    1. Is there any hotfix/patch that SAP can provide for making RCT more robust resulting in elimination of conversion errors/influence the success rate of report conversion?
    2. If no hotfix for RCT is present, can we get quick answers from SAP through the alliance for resolution of these report conversion errors? We have received the below errors when we made an attempt at report conversion
    1.Breaks in Web Intelligence can only be set on objects present in the block
    2 Objects cannot be hidden in Web Intelligence documents
    3.Page setup options are not implemented in Web Intelligence (First page number, page order, scale, Fit to N pages)
    4.Across options for crosstabs are not available in Web Intelligence -5.Detail variables have no associated dimension in Web Intelligence 6.Conditional or permanent Hide Header not available in Web Intelligence 7.Function not available in Web Intelligence
    8.The formula of a global filter in Desktop Intelligence cannot be migrated into a Web Intelligence report filter
    9.A formula from a Desktop Intelligence block filter cannot be migrated into a Web Intelligence block filter
    10.Unsupported 'Do not retrieve data' option
    11.Conditional or permanant Hide Footer does not exist in Web Intelligence
    12.Keyword not available in Web Intelligence
    13.Unsupported Data Provider
    Anticipating your help and cooperation at the earliest. Please let me know if you need any more information.
    Many Thanks & Regards,
    Sandeep

    Report Conversion Tool cannot guarantee 100% conversion rates. It's imposible due to functionality differences that still exist between Full Client/Deski and Webi documents.
    If you have a report that won't convert - you will have to manualy re-create it in Webi. It'll show you if design you use is even possible there or not.
    As to the list of errors you provided - each one has to be reviewed and investigated to see why it happens.
    Like #3 - might be due to the fact that Webi has no page options or #13 might indicate unsupported data provider, lust like the error says.
    You might want to open a support Incident to properly investigate all the errors you received, but keep in mind - 100% conversion is not possible unless you use simplest reports.

Maybe you are looking for

  • HP ENVY 100 D410 Printing issues...

    I have an HP ENVY 100 that has recently started having printing issues.  We recently upgraded to Mountain Lion and had no problems in the upgrade nor have we had any other software that we've changed.  The problem seems to be somewhat random and the

  • Report tries to connect to wrong database

    Hello, We're currently developing an ASP.NET C# Web Application and integrate some Crystal Reports using the CrystalReportViewer control. Our environment looks like this: <h1>Dev Environment:</h1> One machine using - Windows Server 2003 - .NET Framew

  • Problem with installing solaris 10

    hi. I'm using Intel-based processor for my stand-alone computer running Windows XP Professional with a broadband connection. As directed by one of the guys here, and also by my own research, I found the documentation for installing Solaris 10 on x86

  • Adobe Edge 2.01 & Windows 8.1 Incompatible ?

    Bonjour, j'aimerai avoir la confirmation que Windows 8.1 et Edge sont bien incompatible, j'avais déjà un problème la dernière fois au passage de la mise à jour 8 ---> 8.1 (Page de garde du logiciel vide ou bugé, plus de preview et ouverture de fichie

  • Is the BB salesperson lying to me or simply ignora

    Ok. A few days ago, I am shopping at the local BB for a new flash player for my wife. She has a Napster-to-Go membership and likes the idea of renting. I ask the salesperson if the GB Zen Nano Plus is subscription compatible. He assures me that it is