Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 04-09-2003, 01:41 PM   #1 (permalink)
Phatslugga
Registered User
 
Join Date: Apr 2003
Posts: 4
Phatslugga is on a distinguished road
Custom Component

Ok, ive tried learning how to make a custom component, but i didnt grasp on to it very well, i have a program that i need to make a custom component with, it's supposed to have two textfeilds occupying the top area of the window, and under it is supposed to be a custom component, but i dont know exactly how to put it in, the book is kind of sketchy with it too. Here's my code so far
:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Pgm6 extends JFrame
{
private JTextField txt, txt2;
public Pgm6()
{
this.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});

Container c = getContentPane();
c.setLayout(new FlowLayout());

txt = new JTextField(20);
txt2 = new JTextField(20);

c.add(txt);
c.add(txt2);
}

public static void main(String args[])
{
System.out.println("Starting App");
Pgm6 f = new Pgm6();
f.setSize(100,100);
f.show();
Phatslugga is offline   Reply With Quote
Old 04-11-2003, 12:47 AM   #2 (permalink)
Phatslugga
Registered User
 
Join Date: Apr 2003
Posts: 4
Phatslugga is on a distinguished road
update

Well, i tried, and it didnt work, here's what i tried to get the custom component to work.

:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Pgm6 extends JFrame
{
JTextField txt = new JTextField(15), txt2 = new JTextField(15);
JCustom cust = new JCustom();

public Pgm6()
{
this.addWindowListener (new WindowAdapter(){
public void windowClosing(WindowEvent e){
dispose();
System.exit(0);
}
});
Container c = getContentPane();
c.setLayout(new FlowLayout());
c.add(txt);
c.add(txt2);
c.add(cust, BorderLayout.SOUTH);
}



class JCustom extends JPanel
{
public Dimension getPrefferedSize()
{
return new Dimension (50,90);
}

public void paintComponent(Graphics g)
{
super.paintComponent (g);
setBackground(Color.yellow);
}

public JCustom()
{
setLayout (new BorderLayout());
JPanel p = new JPanel();
p.setLayout(new FlowLayout());



}
}
public static void main(String args[])
{
System.out.println("Starting App");
Pgm6 f = new Pgm6();
f.setSize(100,100);
f.show();
}
}

:

I can't seem to get this to work, can somoene give me a clue or tip on how to get that custom component to shwo up under my textfields? thanks
Phatslugga is offline   Reply With Quote
Old 04-13-2003, 12:18 AM   #3 (permalink)
Phatslugga
Registered User
 
Join Date: Apr 2003
Posts: 4
Phatslugga is on a distinguished road
Ok, Totally redone, one small problem

Ok, ive gotten most of it to work, thank god.. anyways My problem is with the border layout. I need two textfields in the NORTH, but when i add both of them, they just become one big textfield. I think that the last one i add just overwrites the one before it. Is there a way i can get around that and put two textfields in the same area? I tried using the GridLayout, but i only have three components to add, and i need the third one centered. The Grid Layout wont let me center the third one, so i cant use it. Anyways Here's my code , if someone can help me, that would be greatly appreciated.
:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Pgm6 extends JFrame
{
private JTextField txt;
private JTextField txt2;
private BorderLayout layout;
private FlowLayout layout2;

private JCustom cust;

public Pgm6()
{
super("Frame Title");

layout = new BorderLayout();


Container c = getContentPane();
c.setLayout(layout);

txt = new JTextField(10);
txt2 = new JTextField(10);

cust = new JCustom();

c.add(txt, BorderLayout.NORTH);
c.add(txt2, BorderLayout.NORTH);
c.add(cust, BorderLayout.CENTER);



setSize(100,100);
setVisible(true);
}


class JCustom extends JPanel
{
public Dimension getPrefferedSize()
{
return new Dimension (50,90);
}

public void paintComponent(Graphics g)
{
super.paintComponent (g);
setBackground(Color.yellow);
}

public JCustom()
{
setLayout (new BorderLayout());
JPanel p = new JPanel();
p.setLayout(new FlowLayout());
add(p,BorderLayout.NORTH);
add(txt,BorderLayout.SOUTH);




}
}

public static void main(String args[])
{
Pgm6 application = new Pgm6();
application.setDefaultCloseOperation(JFrame.EXIT_O N_CLOSE );
}

}

:

There it is, don't laugh . If you compile it, you'll see that there is only one textfield at the top, i need two of them there.
Phatslugga is offline   Reply With Quote
Old 04-13-2003, 04:30 PM   #4 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
okay, i didn't really read any of that, but if you want to components in the BorderLayout.NORTH area, thae just add a panel to the NORTH area instead of your textfield and then add them to that panel, i haven't done any GUI stuff with java for a long time, but that will work

i forget which layout you need, the default for a panel should do it though.. flowlayout is it? i think so

anyway, yes, thats the idea, add a panel to BorderLayouth.NORTH instead of your textfield, and add 2 textfields to that panel
__________________
-- bloomberg.
abc123 is offline   Reply With Quote
Old 04-13-2003, 11:46 PM   #5 (permalink)
Phatslugga
Registered User
 
Join Date: Apr 2003
Posts: 4
Phatslugga is on a distinguished road
....

Wow, that was an easy fix... i can't beleive i didn't think of that... thanks anyways.. but now im jsut ashamed
Phatslugga is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR: Uploading Custom Avatar infinite_root Feedback 6 05-17-2004 04:47 PM
Custom function bdl PHP 3 03-07-2003 06:53 PM


All times are GMT -8. The time now is 12:24 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting