File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "cannot manage layout in the frame" Watch "cannot manage layout in the frame" New topic

cannot manage layout in the frame

suraya ya'acob

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);
TwoLine t = new TwoLine(110,200,200,200);

JPanel panelberat = new JPanel();

Berat b = new Berat(50, 300,100,300);
Berat b = new Berat(50, 300,400,300);

public static void main(String args[])
carian22 aya = new carian22();

class with extends JComponent coding(example just for, 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) {
Graphics2D g2d=(Graphics2D) g;

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: 15302

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
wood burning stoves
subject: cannot manage layout in the frame
jQuery in Action, 3rd edition