Canvas covering scrollbars in JScrollPane

I have an image with listeners, implemented as a Canvas. I add it to a JScrollPane. When This JScrollPane is displayed, I get the Canvas overlapping the scrollbars, but still responding to MouseWheel events. Is seems that it is being painted on top of the JScrollPane instead of behind it. Is there a way to remedy this?
Thanks in advance.
-Nate

nevermind
I got it taken care of.. Stupid question.

Similar Messages

  • How to change the size of the scrollbar in JScrollPane?

    I set a jtable in the jscrollpane,but the table is very small,so I want to change the size of the scrollbar in the jscrollpane.How can i do?Please help me,Thanks.

    Dropping and re-creating the table is by far the best way (of course you need to unload the table's data to a flat file with ttBulkCp first and then reload it again afterwards).
    a second option is to drop the column and re-add it with the new size but you still need to preserve the data first and put it back afterwards and this is harder for a single column than for a whole table. Also, if you are using replication you should exercise care when using ALTER TABLE to ensure iall replicated copies of the table maintain the same physical structure.
    Chris

  • Forms 5 Tab Canvas & Horizontal Scrollbar

    We are trying to implement a tab canvas which will hold a multi-record data block. The difficulty is that we would like to display a lot of fields and there is no Horizontal Scrollbar easily available for the Tab Canvas.
    We are thinking about "simulating" a tab canvas by using stacked canvases. The stacked canvas allows us to have the scrollbar, but looses some of the look & feel of a tab canvas.
    Anyone try to do this in Forms 5? How about anyone try to place a stacked canvas on top of a tab canvas?

    We're using forms 6.0.8.8. Our standard practice is to never put items on a tab canvas, instead we put stacked canvas' on the tab canvas. Besides having canvas scroll bars, it also provides a basis to work around documented bugs for refreshing/resizing windows when returning from other forms/windows of different sizes etc.
    null

  • I need to get the position of scrollBar in JScrollPane

    I have two JTables pleaced in JScrollPanes. User can drag a cell from the first table and drop it on the second. I catch selected row nr in the first tible when dragging starts (using rowAtPoint(e.getPoint())) and when user releases mouse I need to calculate the position on the second table.
    Everything works great but if scrollBar in the first table is scrolled down I have a position of pointWhereMouseIsReleased == pointOnScreen+positionOfScrollBar
    All I need to get is the position of the scroll bar. I tried to use getValue() and so on but it didn't work.
    Any sugestions?
    Thank you,
    Przemek

    ((JViewport)table.getParent()).getViewPosition()will give you the position of the upper-left-hand corner of the viewport, in your JTable's coordinate system. Is that what you need?

  • Vertical ScrollBar in JScrollPane not working

    Hey there chaps,
    I have set up a JScrollPane with a JTextArea but unfortunately find that when I type text past the vertical space - the scrollbar doesnt resize and the focus doesnt remain on the last line typed... Any ideas what i'm doing wrong? Code below..
    thanks...
    {color:#3366ff}
    private JScrollPane getDefaultScrollPane() {{color}
    {color:#008000} JTextArea area = new JTextArea();
    //area.setPreferredSize(textAreaField);
    area.setWrapStyleWord(true);
    area.setLineWrap(true);
    area.setBorder(border);
    JScrollPane pane = new JScrollPane(area);
    pane.setPreferredSize(textAreaField);          pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    return pane;{color}
    {color:#3366ff}
    }{color}

    Welcome to the forum, and congrats on fixing this yourself. You now should give yourself 10 Duke's points. I hope to see you posting here some more, but if you do, please accept one word of advice:
    If you post your code, please use code tags so that your code will be well-formatted and readable. To do this, place the tag [code] at the top of your block of code and the tag [/code] at the bottom, like so:
    [code]
    // your code block goes here
    [/code]
    For instance with tags, your code looks like so:
        private JScrollPane getDefaultScrollPane() {
            JTextArea area = new JTextArea();
            // area.setPreferredSize(textAreaField);
            area.setWrapStyleWord(true);
            area.setLineWrap(true);
            area.setBorder(border);
            JScrollPane pane = new JScrollPane(area);
            pane.setPreferredSize(textAreaField);
            pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
            return pane;
        }This unfortunately is very poorly documented feature of this forum, one I hope is corrected soon. Regardless of this, again, welcome!
    Pete

  • Can't get horizontal scrollbar in JScrollPane to work

    I have a JTable in a JScrollPane and when I load the data the vertical scrollbar shows up and works fine but no horizontal scrollbar shows up even though I have 38 columns in the table. The columns are all very small and even when I manually resize them no scrollbar appears. I have set the scrollbar policy in the JScrollPane to always have a horizontal scrollbar and all that does is show the two arrows at the corners and no bar???

    Maybe you need to call
    yourtable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

  • Customizing the scrollbar for jScrollpane Component

    Hi,
    Am trying to customize my jScrollpane scrollbars. Would like to at least customize colors.
    Anyone know how to do this? Or know anywhere to read up about this. I am using the Sun One Studio and can't seem to do this at all.
    thanks

    I have the same problem.
    So far I have only managed to change the background of the scrollbars.
    jScrollPane.getVerticalScrollBar().setBackground(color);
    Does anyone know how to further customize the scrollbar?

  • How to add seprator to ScrollBar in JScrollPane?

    I have a JScrollPane. I am trying to add border to ScrollBar so ScrollBar looks seprate from pane.
    Is there anyother way to do this so ScrollBar look seprate from scrollPane?? thanks in advance!!!
    thanks
    amit

    Border b = ...; // your border here
    UIManager.put( "ScrollBar.border", b);http://www.gargoylesoftware.com/papers/plafdiff/ScrollBar.html

  • I can't interact (scroll) my scrollbars in JScrollPane on a JPanel

    Hi, I'm having trouble with my textarea with jscrollpane that is on an overidden JPanel to paint a background image. My first problem is that I can't even see the scrollpane but I fixed that through g.setXORMode(true). Now, my problem is even though I can see the component perfectly, when I try to scroll, it won't scroll (unclickable). Is there any way to fix this?
    -I heard that I should try to add the jscrollpane to a component (like JLabel) that's always above the image. But it didn't work. I am not sure i did it right though, so I am looking for other options.
    Anyways, here is the code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.plaf.*;
    import javax.swing.plaf.metal.*;
    import java.util.*;
    public class SrtfMvtDemo extends JFrame implements ActionListener, Runnable {
         public DemoJPanel demoPanel = new DemoJPanel();
         private     JPanel     buttonPanel = new JPanel();
         private     JButton     buttonOpen = new JButton("Open"),
                             buttonStart = new JButton("Start"),
                             //buttonReset = new JButton("Reset"),
                             buttonPause = new JButton("Pause"),
                             buttonAbout = new JButton("About");
         public ImageIcon imageBg = new ImageIcon("img//logo.jpg");
         public ImageIcon imageDiagram = new ImageIcon("img//diagram.gif");
         private int[] xLocations = {550,522,494,466,438,410,382,354,326,298,272,242,
              214,186,158,130,102,74,46,18};
         private int[] xxLocations = {18,46,74,102,130,158,186,214,242,272,298,326,
              354,382,410,438,466,494,522,550};
         public static JLabel[] jqLabels = new JLabel[20];
         public static JLabel[] rqLabels = new JLabel[20];
         public static JLabel[] ioqLabels = new JLabel[20];
         private boolean isStarted = false;
         private boolean isFinished = false;
         public static final Color foreColor = Color.WHITE;
         public static boolean isPaused = false;
         public static JScrollPane scrollpane1;
         public static JScrollPane scrollpane2;
         public static JScrollPane scrollpane3;
         public static MVT memory = new MVT();
         public static CPU cpu = new CPU();
         public static IO ioDevice = new IO();
         public static JobQueue jQueue = new JobQueue();
         public static ReadyQueue rQueue = new ReadyQueue();
         public static IOQueue ioQueue = new IOQueue();
         public static Vector fQueue = new Vector(0,1);
         public static JTextArea cpuGantt = new JTextArea(3,20);
         public static JTextArea ioGantt = new JTextArea(3,20);
         public static JTextArea statistics = new JTextArea(3,30);
         public static JLabel procCpu = new JLabel();
         public static JLabel procIO = new JLabel();
         public static JPanel nonOver = new JPanel();
         public Thread mainThread = new Thread(this);
         public static int nTimer = -1;
         public SrtfMvtDemo() {
              super("INTROOS: SRTF - MVT Algorithm Demonstrator");
              setSize(800,600);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
              setLocationRelativeTo(null);
              setForeground(Color.white);
              setResizable(false);
              getContentPane().setLayout(null);
              buttonOpen.addActionListener(this);
              buttonStart.addActionListener(this);
              buttonPause.addActionListener(this);
              buttonAbout.addActionListener(this);
              buttonStart.setEnabled(false);
              buttonPause.setEnabled(false);
              demoPanel.setLayout(null);
              demoPanel.setSize(800,525);
              demoPanel.setLocation(0,0);
              buttonPanel.setSize(800,75);
              buttonPanel.setLocation(0,526);
              buttonPanel.setLayout(new FlowLayout());
              buttonPanel.add(buttonOpen);
              buttonPanel.add(buttonStart);
              buttonPanel.add(buttonPause);
              buttonPanel.add(buttonAbout);
              getContentPane().add(demoPanel);
              getContentPane().add(buttonPanel);
         private void showUI() {
              //Job Queue Labels
              for(int i=0; i<20; i++) {
                   jqLabels[i] = new JLabel();
                   jqLabels.setVerticalTextPosition(JLabel.CENTER);
                   jqLabels[i].setHorizontalTextPosition(JLabel.CENTER);
                   jqLabels[i].setForeground(Color.white);
                   jqLabels[i].setSize(25,25);
                   jqLabels[i].setLocation(xLocations[i],28);
                   demoPanel.add(jqLabels[i]);
              //Ready Queue Labels
              for(int i=0; i<20; i++) {
                   rqLabels[i] = new JLabel();
                   rqLabels[i].setVerticalTextPosition(JLabel.CENTER);
                   rqLabels[i].setHorizontalTextPosition(JLabel.CENTER);
                   rqLabels[i].setForeground(Color.white);
                   rqLabels[i].setSize(25,25);
                   rqLabels[i].setLocation(xxLocations[i],97);
                   demoPanel.add(rqLabels[i]);
              //IO Queue Labels
              for(int i=0; i<20; i++) {
                   ioqLabels[i] = new JLabel();
                   ioqLabels[i].setVerticalTextPosition(JLabel.CENTER);
                   ioqLabels[i].setHorizontalTextPosition(JLabel.CENTER);
                   ioqLabels[i].setForeground(Color.white);
                   ioqLabels[i].setSize(25,342);
                   ioqLabels[i].setLocation(xLocations[i],97);
                   demoPanel.add(ioqLabels[i]);
              procCpu.setSize(100,20);
              procCpu.setLocation(450,209);
              procCpu.setForeground(Color.white);
              procCpu.setBackground(Color.black);
              demoPanel.add(procCpu);
              procIO.setSize(100,20);
              procIO.setLocation(450,374);
              procIO.setForeground(Color.white);
              procIO.setBackground(Color.black);
              demoPanel.add(procIO);
              cpuGantt.setBackground(Color.black);
              cpuGantt.setForeground(Color.white);
              cpuGantt.setEditable(false);
              cpuGantt.setLineWrap(true);
              cpuGantt.setWrapStyleWord(true);
              cpuGantt.setSize(557,47);
              cpuGantt.setLocation(15,162);
              cpuGantt.setAutoscrolls(true);
              //demoPanel.add(cpuGantt);
              scrollpane1 = new JScrollPane(cpuGantt,
                   JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                   JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              scrollpane1.setSize(557,47);
              scrollpane1.setLocation(15,162);
              //demoPanel.add(scrollpane1);
              ioGantt.setBackground(Color.black);
              ioGantt.setForeground(Color.white);
              ioGantt.setEditable(false);
              ioGantt.setLineWrap(true);
              ioGantt.setWrapStyleWord(true);
              ioGantt.setSize(557,47);
              ioGantt.setLocation(15,327);
              ioGantt.setAutoscrolls(true);
              //demoPanel.add(ioGantt);
              scrollpane2 = new JScrollPane(ioGantt,
                   JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                   JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              scrollpane2.setSize(557,47);
              scrollpane2.setLocation(15,327);
              //demoPanel.add(scrollpane2);
              statistics.setBackground(Color.black);
              statistics.setForeground(Color.white);
              statistics.setEditable(false);
              statistics.setLineWrap(true);
              statistics.setWrapStyleWord(true);
              statistics.setSize(760,100);
              statistics.setLocation(18,405);
              statistics.setAutoscrolls(true);
              //demoPanel.add(statistics);
              scrollpane3 = new JScrollPane(statistics,
                   JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                   JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              scrollpane3.setSize(760,100);
              scrollpane3.setLocation(18,405);
              //demoPanel.add(scrollpane1);
              //demoPanel.add(scrollpane2);
              //demoPanel.add(scrollpane3);
              nonOver.setLayout(null);
              nonOver.setSize(800,525);
              nonOver.setLocation(0,0);
              nonOver.setOpaque(false);
              nonOver.add(scrollpane1);
              nonOver.add(scrollpane2);
              nonOver.add(scrollpane3);
              demoPanel.add(nonOver);
         public static void main(String[] args) {
              MetalLookAndFeel.setCurrentTheme(new JetTheme());
              try {
                   UIManager.setLookAndFeel(new MetalLookAndFeel());
              } catch(Exception e) {}
              setDefaultLookAndFeelDecorated(true);
              JDialog.setDefaultLookAndFeelDecorated(true);
              SrtfMvtDemo mainDemo = new SrtfMvtDemo();
              mainDemo.setVisible(true);
         public void actionPerformed(ActionEvent ae) {
              if(ae.getSource()==buttonOpen) {
                   Opener open = new Opener();
                   isStarted = open.doOpen();
                   if(isStarted) {
                        buttonStart.setEnabled(true);
                        buttonPause.setEnabled(true);
              if(ae.getSource()==buttonStart) {
                   buttonOpen.setEnabled(false);
                   buttonStart.setEnabled(false);
                   showUI();
                   isStarted = true;
                   showUI();
                   mainThread.start();
              if(ae.getSource()==buttonPause) {
                   isPaused = !isPaused;
              if(ae.getSource()==buttonAbout) {
                   JOptionPane.showMessageDialog(null, "This machine project is made "+
                        "by:\nAndrei Victor\nJohanne Pagaduan\nOliver Recio\nINTROOS S11",
                        "About", JOptionPane.INFORMATION_MESSAGE);
         public void run() {
              do {
                   while(!isPaused) {
                        if(fQueue.size() > 0 && fQueue.size() == Job.getNumberOfJobs()) {
                             isFinished = true;
                             break;
                        try {
                             mainThread.sleep(10);
                        } catch(Exception e) {
                        nTimer++;
                        System.out.println("Time: " + nTimer);
                        if(cpu.currentJob != null)
                             System.out.println("J"+cpu.currentJob.getID()+" Burst: "+cpu.currentJob.getBurst());
                        jQueue.check();
                        rQueue.check();
                        cpu.check();
                        ioQueue.check();
                        ioDevice.check();
                        repaint();
              } while(!isFinished);
              JOptionPane.showMessageDialog(null, "Simulation Finished", "Sim Info",
                   JOptionPane.INFORMATION_MESSAGE);
         public class DemoJPanel extends JPanel {
              //Do your paint stuff here!
              public DemoJPanel() {
                   setDoubleBuffered(true);
              public void paintComponent(Graphics g) {
                   super.paintComponent(g);
                   if(!isStarted) {
                        g.drawImage(imageBg.getImage(), 0, 0, this);
                   } else {
                        g.drawImage(imageDiagram.getImage(), 0, 0, this);
                        g.drawString("Time: " + nTimer, 700, 370);
                        g.setXORMode(Color.black); //this lets me see through the image
                                                           //but doesn't let me interact with it.
                        for(int i=0; i<64; i++) {
                             if(memory.memory[i] != -1)
                                  g.setColor(new Color(128,47,249));
                             else
                                  g.setColor(new Color(0,0,0));
                             g.fill3DRect(655,28+(i*4)+i,125,4,true);
         /** JetTheme class to change the color of the L&F of the Metal theme.
    public static class JetTheme extends DefaultMetalTheme {
    /** Method to return the theme name.
    public String getName() { return( "Jet" ); }
    private final ColorUIResource primary1 =
    new ColorUIResource(80,80,80);
    private final ColorUIResource primary2 =
    new ColorUIResource(90,90,90);
    private final ColorUIResource primary3 =
    new ColorUIResource(50,50,50);
    private final ColorUIResource secondary1 =
    new ColorUIResource(0,210,0);
    private final ColorUIResource secondary2 =
    new ColorUIResource(0,140,0);
    private final ColorUIResource secondary3 =
    new ColorUIResource(0,0,0);
    private final ColorUIResource black =
    new ColorUIResource(0,255,0);
    private final ColorUIResource white =
    new ColorUIResource(0,0,0);
              protected ColorUIResource getPrimary1() { return( primary1 ); }
              protected ColorUIResource getPrimary2() { return( primary2 ); }
              protected ColorUIResource getPrimary3() { return( primary3 ); }
              protected ColorUIResource getSecondary1() { return( secondary1 ); }
              protected ColorUIResource getSecondary2() { return( secondary2 ); }
              protected ColorUIResource getSecondary3() { return( secondary3 ); }
              protected ColorUIResource getBlack() { return( black ); }
              protected ColorUIResource getWhite() { return( white ); }

    This is how I paint a background image:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=316074

  • MouseDragged on canvas, and JScrollPane

    Hi,
    I have created a canvas which appear transparent in front of the JScrollPane.
    How to make the ScrollBar in JScrollPane scrolling down while the mouse is drag on the canvas?
    Here is my code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.awt.geom.*;
    public class Try extends JFrame{
         JPanel all = new JPanel(new BorderLayout());
         JPanel main = new JPanel(new BorderLayout());
         DisplayCanvas canvas;
         JScrollPane scroll;
         JButton btn1;
         public Try(){
              super("Trying");
              setResizable(false);
              canvas = new DisplayCanvas();
              scroll = new JScrollPane(new JLabel(new ImageIcon("contain.jpg")));
              scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
              scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              main.add(scroll);
              canvas.setOpaque(false);
              all.add(main,BorderLayout.CENTER);
              all.setBounds(55,82,240,319);
              setContentPane(new JLabel(new ImageIcon("myBorder.gif")));
              getContentPane().add(canvas);
              getContentPane().add(all);
              addWindowListener(new WindowEventHandler());
              pack();
              setVisible(true);
              class WindowEventHandler extends WindowAdapter{
                   public void windowClosing(WindowEvent e){
                        System.exit(0);
              public static void main(String args[]){
                   new Try();
    class DisplayCanvas extends JPanel{
         BufferedImage bi;
         AffineTransform at;
         double x;
         DisplayCanvas(){
              setBounds(55,105,239,295);
              addMouseMotionListener(new MouseMotionHandler());
              Image image = getToolkit().getImage("line.gif");
              MediaTracker mt = new MediaTracker(this);
              mt.addImage(image,1);
              try{
                   mt.waitForAll();
              }catch (Exception e){
                   System.out.println("Exception while loading image.");
              if(image.getWidth(this)==-1){
                   System.out.println("Make sure image line.jpg is in the same directory");
                   System.exit(0);
              bi = new BufferedImage(image.getWidth(this),image.getHeight(this),BufferedImage.TYPE_INT_ARGB);
              Graphics2D big = bi.createGraphics();
              big.drawImage(image,0,0,this);
              at = new AffineTransform();
              at.translate(getWidth()/2, getHeight()/2);
         public void paintComponent(Graphics g){
              super.paintComponent(g);
              Graphics2D g2D = (Graphics2D)g;
              AffineTransform saveXform = g2D.getTransform();
              at.rotate(Math.toRadians(x));
              AffineTransform toCenterAt = new AffineTransform();
              toCenterAt.concatenate(at);
              toCenterAt.translate(-(getWidth()/2),-(getHeight()/2));
              g2D.transform(toCenterAt);
              g2D.drawImage(bi,150,200,this);
              g2D.setTransform(saveXform);
         class MouseMotionHandler extends MouseMotionAdapter{
              public void mouseDragged(MouseEvent e){
                   x = 5;
                   repaint();
    }

    Already answered here:
    http://forum.java.sun.com/thread.jspa?threadID=5148607

  • JScrollPane in a JFrame scrollbars visible but not functional no thumbtabs

    Here is the code that I compiled and run on J2SE v. 1.4.2 (runtime b28). I looked through the various related articles and nothing seems to help with this issue. The scrollbars appear along with the panel but the thumbtabs are not present. Any help would be appreciated.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Test {
      public static void main(String[] args){
        Test rce = new Test();
        JFrame frame = new JFrame("Test Scroll");
        JScrollPane scrollBar = new JScrollPane();
        scrollBar.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollBar.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        Component  rcePage = rce.createComponents();
        scrollBar.getViewport().add(rcePage, null);
        frame.getContentPane().add(scrollBar, null);
        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        frame.pack();
        frame.setSize(400, 400);
        frame.setVisible(true);
      public Component createComponents() {
        JPanel pan = new JPanel();
        JLabel label = new JLabel("This is a Test!");
        pan.setBorder(BorderFactory.createEmptyBorder(
            0, //top
            0, //left
            0, //bottom
            0) //right
        pan.setLayout(null);
        label.setBounds(100, 100, 80, 20);
        pan.add(label);
        return pan;
    }

    This is a very common mistake. When you put a JPanel in a scrollpane, the scrollpane will use the panel's preferred size to determine if scrolling is needed or not. If the panel is using a LayoutManager this is generally done for you automatically. But in your case you set the layout to null, and then it is your responsibility to make sure that the getPreferredSize() method of the panel returns the correct size.
    One way to fix this in the code you posted would be to override the getPreferredSize() of the panel, like so:
        public Component createComponents() {
            JPanel pan = new JPanel() {
                public Dimension getPreferredSize() {
                    return getSize();
        }Then the scrollbars will appear if you make the frame smaller.
    But what I really suggest is that you use a LayoutManager.

  • Update the scrollbars of a JScrollPane

    Hi,
    I have a component in a JScrollPane. But when it changes its preferredSize the scrollbars of JScrollPane aren't updated automatically.
    I've tried:
    myComponent.getParent().repaint(); // JViewPort
    myComponent.getParent().getParent().repaint(); // JScrollPaneneither had the desired effect :-(
    Can anybody help?
    Thanks!
    Greez
    Puce

    It worked with revalidate(), but thanks, it led me on the right path.
    But why isn't it called automatically as stated in the Javadoc of JComponent?
    A bug?
    - Puce

  • Scrollbar for Tab canvas

    Hi
    I have added a scrollbar on window for Tab canvas but remains inactive even the layout goes beyond the window.But it works for Content canvas.
    Can somebody plz tell me is there any way to use scroll bar for tab canvas
    Ravi

    The scrollbar works for tab canvases as well as content canvases. Not sure what you mean by "remains inactive even the layout goes beyond the window".

  • Popup menu appears behind canvas component

    Has anybody encountered this problem?
    I attach the popup menu to the canvas component, like this:
    public void mousePressed(MouseEvent e)
         if (e.getSource() == psuCanvas && e.getButton() == MouseEvent.BUTTON3)
              pmenu.show((Component)psuCanvas, e.getX(), e.getY());
              contextText.setText("Right Click!!!");
    The popup menu is only visible when I click the edge of the Canvas component, that is how I know that the popup is actually showing but behind the Canvas component!!!
    Please help

    You mean your 1 step of calling "JPopupMenu.setDefaultLightWeightPopupEnabled(false);"?
    That method is meant specifically for using popup menus when you are mixing AWT and Swing components. The reason is because of the problem you first posted about. It's a way to get around that problem. But really, it's more of a hack that is used when dealing with old AWT-based components which you can't (or won't), for whatever reason, "update" to Swing versions. (Say from a 3rd-party library).
    It is not recommended to mix AWT and Swing components, as already mentioned. The provided link above is an article that explains the issues with this. The fact that you can doesn't mean you should.
    If you are writing this Canvas subclass yourself, and it's going to be typically used in a Swing application, you will have problems later, most likely. For example, why don't you try puting your Canvas class in a JScrollPane so you can make it bigger then the window and scrollable? You'll have scrollbar visibility issues. Fine, you can use java.awt.ScrollPane, I guess. Then I can think of several things one might do with JLayeredPanes which would create problems as well. And there is no simple "setDefaultLightWeightEnabled()" option to fix those.
    So eventually, as your app, or library, matures, you start running into these problems cuz you are using AWT components where you should be using Swing components, and you start making more hack-like fixes for all these problems like using setDefaultLightWeightPopupEnabled() and explicit sizing instead of layout managers and limiting yourself to what you can do with your components.
    That's why.

  • JTextPane in JScrollPane... Scrolling when needed

    Hello all.
    I have a jtextpane in a jscrollpane and I'm using the following code to append a line in jtextpane and set the vertical scrollbar of jscrollpane at the bottom...
      htmlDoc = (HTMLDocument) output.getDocument();
      htmlKit.insertHTML(htmlDoc, htmlDoc.getLength(), s, 0, 0, null);
      output.setCaretPosition(htmlDoc.getLength());where output is the jtextpane.
    My problem is that, if the user manually changes the position of the vertical scrollbar, after appending a new line in jtextpane, the above code will set the scrollbar at the bottom.
    Is it possible to keep the scrollbar at the position it was before the new line has been appended (if the position of the scrollbar has been changed)?
    Thanks in advance,
    Charalampos

    StanislavL... with your suggestion the scroll bar will never scroll to the bottom.
    I want to place the scroll bar at the bottom if it was at the bottom before I append text to jtextpane, otherwise I want to leave the scroll bar at the same position it was before I append the text.

Maybe you are looking for

  • Need some help with Photoshop Elements Organizer

    I have had this program for awhile now, but have not had a lot of time to spend with it....also on a new Mac. I am trying to work with the Organizer.  First time I tried to import photos from IPhoto, it said there was no media to import....(I have a

  • Xdim_member  - How to use it

    Hi, Does  xdim_member  is still available for BPC 7.5 SP04 ? Im trying to make a change in my  scripts, taking as a base this: acc1 = account.x.category.budget acc2 = account.y.category.budget acc3 = account.z.category.budget now: xdim_member categor

  • Keyboard - Wear and Tear

    Hi all Have a small problem with my keyboard. Because my fingers and thumbs are on the large side, I tend to use my fingernails to press the keys - I much prefer the actual keyboard to the virtual one. Anyhow the other day when the keyboard light cam

  • NLS_LENGHT_SEMANTICS

    Hi, I have a requirement that the database must be having CHAR instead of BYTE as its semantics because during migration it is causing issues. When i check the database using, SQL> show parameter nls_LENGTH_SEMANTICS; NAME TYPE VALUE nls_length_seman

  • Best quality encode settings? Handbrake?

    Hi Gang, So, if I want to encode the best quality video for Apple TV, what settings would I want to use...say in Handbrake? I want to make a true HD slideshow to show in our photo studio. Thanks for any advice! Rob