Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
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
Forum:
Swing / AWT / SWT
My scrollbars are not displaying
shalini gnana
Ranch Hand
Posts: 189
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Why my scrollbars are not getting displayed..Where do i gone wrong?
package javaapplication5; import java.awt.event.MouseListener; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.text.DateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import javax.swing.*; import java.awt.*; import java.awt.BorderLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Main extends JApplet { String s= "aswedfrtyhgqwsadrftlopqasnhfgrchildnode1"; int width = s.length(); JScrollPane scroll ; int border = 2; int margin = 10; int rectx = margin+border,recty =margin+border+63; int rectwidth = 8, rectheight = 6; int imgborder = 10; int imgline1 = 300; int labellocx = rectx+imgborder+13; int labellocy = recty+imgborder-1; int circlex = rectx+rectwidth; int circley = recty+rectheight; int x =rectx+rectwidth+10; int y = recty+rectheight+10; int x1 = x+17; int y1 = y+20; int titlebarx= 300; int titlebary = 40; boolean title = true; String date[] = {"0","4","8","12","16","20","24"}; String day[] = {"Mon","Tue","Wed","Thu","Fri","Sat"}; int width1 = 180; // int f2= x+168; int n =180; // int dayx = 385; long From,To; double Difference; long days; ArrayList dateList; Calendar calendar; Imagepanel image; public void init() { Container cont = getContentPane(); // to see the scrollpane, the scrollpane has to be smaller // then the component held within its viewport setPreferredSize(new Dimension(300, 300)); // getContentPane().add(scroll, BorderLayout.CENTER); image = new Imagepanel(); add(image); } private class Imagepanel extends JPanel implements MouseListener { JLabel label; //JScrollPane scroll = new JScrollPane(); Rectangle rect = new Rectangle(rectx,recty,rectwidth,rectheight); Ellipse2D.Double circle = new Ellipse2D.Double(x,y,4,4); Ellipse2D.Double circle1 = new Ellipse2D.Double(x+10,y+10,4,4); boolean selected = false; boolean selected1 = false; int w ; Imagepanel() { // setting the component to be largenr than the scrollpane // just so we'll see scrollbars. dateList = new ArrayList(); setPreferredSize(new Dimension(32710,32710)); scroll = new JScrollPane(); scroll.getViewport().add(this); // add(scroll); addMouseListener(this); label = new JLabel(); label.setFont(new Font(" Verdana",Font.PLAIN,10));// scroll.add(label); add(label); label.getPreferredSize(); label.setLocation(labellocx,labellocy); setBorder(BorderFactory.createLineBorder(Color.BLACK, border)); From = new java.util.GregorianCalendar(2007,01,01).getTime().getTime(); To = new java.util.GregorianCalendar(2007,06,30).getTime().getTime(); Difference = To-From; days = Math.round((Difference/(1000*60*60*24))); int noday = (int)days; System.out.println(noday); for(int i =0;i<dateList.size();i++) { System.out.println(dateList.get(i)); } } protected void paintComponent(Graphics g) { int x = 300; int x1=300; int x2=x; int daydx=(width1/2); int dayx =daydx +x; int f2= x+168; super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); Font font = new Font("Ariel",Font.PLAIN,11); Font font1 = new Font("Ariel",Font.PLAIN,9); g2.setBackground(Color.GRAY); //drawing the tilte bar g2.setBackground(Color.WHITE); g2.drawLine(imgline1,0,imgline1,getHeight()); g2.setPaint(new Color(0,128,192)); g2.fillRect(imgborder,imgborder,290,45); //g2.setPaint(Color.GRAY); //g2.setStroke(new BasicStroke(2)); //g2.setPaint();m //g2.drawLine(margin,margin,titlebarx,titlebary); //drawing the root node and labeling g2.draw(rect); g2.setPaint(Color.WHITE); g2.drawLine(margin,margin,titlebarx,titlebary); g2.drawString("RESOURCE",40,40); g2.drawString("TIME",200,25); rect.setLocation(rectx,recty); rect.setSize(rectwidth,rectheight); g2.setPaint(Color.BLACK); g2.drawString(" aswedfrtyhgqwsadrftlopqasnhfgrchildnode1",rectx+rectwidth+05,recty+rectheight); for (int i = 0;i<180;i++) { for (int j=0;j<6;j++) { g2.setFont(font1); g2.drawLine(x1,40,x1,35); g2.drawString(date[j],x1,35); // g2.drawString(day[j],dayx,20); g2.drawString("24",f2,35); f2+=width1; x1+=30; // dayx=+170; } g2.drawRect(x,10,width1,30); x+=width1; } for(int k=0;k<n;k++) { for(int l=0;l<6;l++) { g2.drawString(day[l],dayx,20); dayx+=180; } } //dividing the drawing panel //drawing for the click event if(selected) { Color color = Color.orange; g2.fill(circle); g2.draw(circle); // g2.drawRoundRect(x+30,y+15,200,12,5,5); g2.drawString("aswedfrtyhgqwsadrftlopqasnhfgrchildnode1",x+15,y+5); g2.drawRect(300,y,100,15); } if(selected1) { g2.setFont(new Font("Arial",Font.PLAIN,12)); g2.fill(circle1); g2.draw(circle1); g2.drawString(" aswedfrtyhgqwsadrftlopqmasnhfgrchildnode1",x1+15,y1+5); } } public ArrayList getDatesBetween(Date fromDate, Date toDate) { Calendar calendar = Calendar.getInstance(); dateList = new ArrayList(); fromDate = new Date(2007/01/01); toDate = new Date(2007/01/10); if (fromDate.before(toDate)) { Date dateCounter = fromDate; dateList.add(fromDate); while (dateCounter.before(toDate)) { calendar.setTime(dateCounter); int nextDate = calendar.get(Calendar.DATE) + 1; calendar.set(Calendar.DATE,nextDate); dateCounter = calendar.getTime(); DateFormat df= DateFormat.getInstance(); String date = df.format(dateCounter); dateList.add(dateCounter); } }else if(!fromDate.before(toDate) && !fromDate.after(toDate)){ dateList.add(fromDate); } return dateList; } public void update(Graphics g) { paint(g); } public void mouseClicked(MouseEvent e) { //imagePaneMouseClicked(e); } private void imagePaneMouseClicked(MouseEvent e) { Point p = e.getPoint(); if (rect.contains(p)) { if (!selected) { selected = true; repaint(); } } if(circle.contains(p)) { if(!selected1) { selected1 = true; repaint(); } } if(rect.contains(p)) { if(e.getClickCount() == 2) { selected = false; repaint(); } } } public void mousePressed(MouseEvent e) { imagePaneMouseClicked(e); } public void mouseReleased(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } } }
Ulf Dittmer
Rancher
Posts: 43081
77
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
"scroll" is null at the time you're adding it to the content pane. It needs to be initialized at that time (and
you should
definitely not do that in the ImagePanel class, but in the init method of the
applet
).
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Popup menu not responding with mouse event
Messagebox with Mouseevent
looking for a graphical representation
AWT Background Problem
Dispalying random dates
More...