🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.java.gui
1 messages
1 total messages Started by Andreas Raschle Fri, 30 Jan 1998 00:00
JScrollPane: No ScrollBar with my JComponent
#74
Author: Andreas Raschle
Date: Fri, 30 Jan 1998 00:00
141 lines
4796 bytes
Dear reader

The example JScrollPane works well, it loads its image ( a gif file) and
shows the ScrollBars on both sites if needed:

public class TigerPanel extends JPanel{
  public TigerPanel() {
    setLayout(new BorderLayout());
    Icon BigTiger = new ImageIcon ("BigTiger.gif");
    JLabel TigerLabel = new JLabel (BigTiger);
    JScrollPane TigerPane = new JSCrollPane();
    TigerPane.getViewport().add(TigerLabel);
    add(TigerPane,BorderLayout.CENTER);
  }
}

Now I'd like (I'm told to do that ;-) to paint my pixels to a new image.

The problems/questions are:
- When I use a JComponent instead, which has its own Image 
  with createImage() outside of JComponent.paint(), createImage()
  doesn't work.
- Even the Image is larger than the JComponent, no ScrollBars will
  appear.
- My Graphic can change its ZoomFactor, would that be a problem for
  JLabel (JLabel is thought for Images, which do not change their size)
- Where can I get an example of the JScrollPanel with a self painted
  image? (I scanned many FAQ's and the Online-Tutorial from JDC)

Following there is my sample application, which represents my problem.

Thank you for every hint in advance
Andy

PS: I'm developping with jdk 1.1.5 with swing 0.7 on WinNT4.0 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Andreas Raschle          + phone:  ++41 (0)52 267 77 29 (b)
Wiesenstr. 55            +         ++41 (0)52 765 15 60 (p)
8552 Felben-Wellhausen   + fax  :  ++41 (0)52 268 71 09
Switzerland              + www  :  http://www.twi.ch/~ras
                         + UIN  :  5423307 (www.mirabilis.com)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

ArrayTest.java
###############################################################
import com.sun.java.swing.*;

public class ArrayTest extends JFrame implements ActionListener
{
  JMenuItem item,FileExitMenuItem;
  JScrollPane Pane;
  JViewport MyViewport;
  
  public ArrayTest()
  {
    super("My Swing Viewer");
    setSize(800, 600);
    showWindowElements();
  }
  
  public void showWindowElements()
  {
    JMenuBar jmb = new JMenuBar();
    JMenu file = new JMenu ("File");
    file.add (item = new JMenuItem ("New"));
    item.addActionListener (this);
    file.add (item = new JMenuItem ("Open"));
    item.addActionListener (this);
    file.addSeparator();
    file.add (FileExitMenuItem = new JMenuItem ("Close"));
    item.addActionListener (this);
    jmb.add (file);
    setJMenuBar (jmb);
    Pane = new JScrollPane();
    Pane.setPreferredSize(new Dimension(700, 300));
    MyViewport = Pane.getViewport();
    JComponent bigTiger = new CMyImageIcon();
    MyViewport.add(bigTiger);
    getContentPane().add(Pane);
  } // showWindowelements()
    
  public void actionPerformed (ActionEvent evt) {
    Object Source = evt.getSource();
    if (Source == FileExitMenuItem) {
      dispose();
      System.exit(0);
    } //FileExitMenuItem
    
  }
    
  public static void main(String argv[]){
    ArrayTest MyArray = new ArrayTest();
    MyArray.setLocation(200,100);
    MyArray.show();
  } // main
}
 
CMyImageIcon.java:
##############################################################

import com.sun.java.swing.*;

public class CMyImageIcon extends JComponent
{
  Image OffImage;
  Graphics OffGraphics;
  int Width = 850;
  int HeightInit = 650;
  
  public CMyImageIcon ()
  {
    super ();
  }
  
  private void drawOffImage(Graphics g)
  {
    int X = 0; int Y = 0;
    int W = 80; int H = 160;
    int Start = 0; int Arc = 270;
    g.drawArc (X,Y,W,H,Start,Arc);
    W = 120; H = 120; 
    X = Width - W;
    Y = 0;
    Start = 90; Arc = -270;
    g.drawArc (X,Y,W,H,Start,Arc);
  }

  protected void paintComponent(Graphics g)
  {
    if (OffImage == null)
    {  
      OffImage = createImage (Width, HeightInit);
      OffGraphics = OffImage.getGraphics();
      drawOffImage (OffGraphics);
    }
    g.drawImage(OffImage,0,0,Width,HeightInit,
      0,0,Width,HeightInit,this);
  }
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads