*
The moose likes Swing / AWT / SWT and the fly likes cannot manage layout in the frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "cannot manage layout in the frame" Watch "cannot manage layout in the frame" New topic
Author

cannot manage layout in the frame

suraya ya'acob
Greenhorn

Joined: May 10, 2003
Posts: 25
I'm drawing a line using a class with extends JComponent. So when i want to have many lines, i have to import many classes. The problem is, i've tried using gridLayout and borderLayout to manage the layout in JFrame but the lines didnt appear... below is my coding..
please help me
My main coding...............
import java.awt.*;
import java.awt.Container;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.JPanel;
import javax.swing.ImageIcon;
import javax.swing.border.*;
import java.awt.image.*;
import java.sql.*;
import java.util.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.text.*;
class carian22 extends JFrame{

public carian22()
{

Container pane=getContentPane();
//pane.setLayout (new BorderLayout());
JPanel grafik = new JPanel();
grafik.setLayout(new GridLayout(2,1));

JPanel timeline = new JPanel();
timeline.setLayout(new GridLayout(1,2));
OneLine o = new OneLine(20,200,100,200);
timeline.add(o);
TwoLine t = new TwoLine(110,200,200,200);
timeline.add(t);

JPanel panelberat = new JPanel();

Berat b = new Berat(50, 300,100,300);
panelberat.add(b);
grafik.add(timeline);
grafik.add(panelberat);
pane.add(grafik);
/*
Berat b = new Berat(50, 300,400,300);
pane.add(b);
*/
setBounds(0,0,1024,730);
setVisible(true);
}

public static void main(String args[])
{
carian22 aya = new carian22();
aya.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

class with extends JComponent coding(example just for OneLine.java, same goes to the rest..)
import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import java.awt.*;
public class OneLine extends JComponent {
private int x,y,x2,y2,tebal, warna;
int tinggi, kaler;
public OneLine(int x, int y, int x2, int y2) {
this.x = x;
this.y = y;
this.x2 = x2;
this.y2 = y2;

}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d=(Graphics2D) g;

g2d.drawLine(x,y,x2,y2);
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getX2() {
return x2;
}
public void setX2(int x2) {
this.x2 = x2;
}
public int getY2() {
return y2;
}
public void setY2(int y2) {
this.y2 = y2;
}
}
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Why don't you use a JSeperator instead of reinventing the wheel? It's not just for Menu and Tool Bars. You can use it just like any other component in SWING.


GenRocket - Experts at Building Test Data
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot manage layout in the frame
 
Similar Threads
how to Draw, mouse dragged points on JPane and Save it
drawing arrows
Dynamic panel ...
draw dynamic lines
Parallel dragging