Titled Border

Hello everyone! i have a slight problem with my titled border!!!
[79 byte] By [hello.everyonea] at [2007-11-27 6:38:24]
# 1

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.text.*;

import java.awt.font.*;

import javax.swing.border.AbstractBorder.*;

import javax.swing.border.TitledBorder.*;

import javax.swing.border.*;

public class slss {

public slss() {

JFrame frame = new JFrame();

JPanel cp = (JPanel)frame.getContentPane();

cp.setLayout(null);

TitledBorder border1 = new TitledBorder( "Sports");

frame.add(border1);

frame.setSize(1280,775);

frame.setLocationRelativeTo(null);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

}

public static void main(String[] args) {

new slss();

}

}

hello.everyonea at 2007-7-12 18:07:02 > top of Java-index,Java Essentials,Java Programming...
# 2
sorry to hear that!
TuringPesta at 2007-7-12 18:07:02 > top of Java-index,Java Essentials,Java Programming...
# 3
lol i know...are you good with programming java?
hello.everyonea at 2007-7-12 18:07:02 > top of Java-index,Java Essentials,Java Programming...
# 4
This is not how you do this:JPanel cp = (JPanel)frame.getContentPane();useContainer cp = frame.getContentPane() instead.What problem are you having?
TuringPesta at 2007-7-12 18:07:02 > top of Java-index,Java Essentials,Java Programming...
# 5
cannot find symbol method add(javax.swing.border.TitledBorder)same error after i tried ur way to tho
hello.everyonea at 2007-7-12 18:07:02 > top of Java-index,Java Essentials,Java Programming...
# 6
Use frame.setBorder(yourBorderHere).
Againa at 2007-7-12 18:07:02 > top of Java-index,Java Essentials,Java Programming...
# 7
now two of those errors pop upare u trying this too in a java based text editor?
hello.everyonea at 2007-7-12 18:07:02 > top of Java-index,Java Essentials,Java Programming...
# 8

Next time please post these questions the Swing forums

and check the online tutorials.

http://java.sun.com/docs/books/tutorial/uiswing/components/border.html

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.text.*;

import java.awt.font.*;

import javax.swing.border.AbstractBorder.*;

import javax.swing.border.TitledBorder.*;

import javax.swing.border.*;

public class slss {

// http://java.sun.com/docs/books/tutorial/uiswing/components/border.html

public slss() {

JFrame frame = new JFrame();

Container cp = frame.getContentPane();

cp.setLayout(null);

TitledBorder border1 = new TitledBorder( "Sports");

if(cp instanceof JComponent){

((JComponent)cp).setBorder(border1);

}

frame.setSize(1280,775);

frame.setLocationRelativeTo(null);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

}

public static void main(String[] args) {

new slss();

}

}

TuringPesta at 2007-7-12 18:07:02 > top of Java-index,Java Essentials,Java Programming...
# 9
dude ur a genioius...u did it so fast thanks alot man
hello.everyonea at 2007-7-12 18:07:02 > top of Java-index,Java Essentials,Java Programming...
# 10

by the way, this is how you should REALLY be accomplishing this.

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.text.*;

import java.awt.font.*;

import javax.swing.border.AbstractBorder.*;

import javax.swing.border.TitledBorder.*;

import javax.swing.border.*;

public class SLSS{

public static void main(String[] args){

new SLSS();

}

public SLSS(){

border1 = new TitledBorder( "Sports");

panel = new JPanel();

panel.setBorder(border1);

frame = new JFrame();

frame.setContentPane(panel);

frame.setSize(1280,775);

frame.setLocationRelativeTo(null);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

}

TitledBorder border1;

JPanel panel;

JFrame frame;

}

TuringPesta at 2007-7-12 18:07:02 > top of Java-index,Java Essentials,Java Programming...
# 11
and b4 i let u go is there a way of moving to the next line without getting error msges
hello.everyonea at 2007-7-12 18:07:02 > top of Java-index,Java Essentials,Java Programming...
# 12

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.text.*;

import java.awt.font.*;

import javax.swing.border.AbstractBorder.*;

import javax.swing.border.TitledBorder.*;

import javax.swing.border.*;

public class slss {

// http://java.sun.com/docs/books/tutorial/uiswing/components/border.html

public slss() {

JFrame frame = new JFrame();

Container cp = frame.getContentPane();

cp.setLayout(null);

TitledBorder border1 = new TitledBorder( "2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007

2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 ");

if(cp instanceof JComponent){

((JComponent)cp).setBorder(border1);

}

frame.setSize(1280,775);

frame.setLocationRelativeTo(null);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

}

public static void main(String[] args) {

new slss();

}

}

hello.everyonea at 2007-7-12 18:07:02 > top of Java-index,Java Essentials,Java Programming...
# 13

First, dont use that code use the proper form I just posted.

Second, yes, lol.

Just make them separate strings and join them with +

"string 1" + "string 2" etc.

TitledBorder border1 = new TitledBorder( "2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007" +

"2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 ");

TuringPesta at 2007-7-12 18:07:02 > top of Java-index,Java Essentials,Java Programming...
# 14
the one u showed me is the same thing i guess ts just that i dont understand it much so i rather stick with the first one until im more into java..only 6 months in...but thanks alot everyone for helping me on my first problem
hello.everyonea at 2007-7-12 18:07:02 > top of Java-index,Java Essentials,Java Programming...
# 15

You can't break String literals onto multiple lines like that. If you want to split it onto multiple lines, make it into two literals concatenated with +:

String s = "This is a

multi-line String";// wrong

String s = "This is a " +

"multi-line String";// right

If you're trying to display a multile line title in the border, I don't know if that's possible, but "\n" is a newline character, you can try that.

String s = "This is a \nmulti-line String";

hunter9000a at 2007-7-21 22:00:10 > top of Java-index,Java Essentials,Java Programming...
# 16
That first code is completely wrong. Its also MANY times more difficult to understand.The 2nd version (which is correct) seems like it would be easier for a beginner to understand.
TuringPesta at 2007-7-21 22:00:10 > top of Java-index,Java Essentials,Java Programming...
# 17

now a second issue proberly something easy...my titled border only fills the top not the sides and the bottom

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.text.*;

import java.awt.font.*;

import javax.swing.border.AbstractBorder.*;

import javax.swing.border.TitledBorder.*;

import javax.swing.border.*;

public class slss {

// http://java.sun.com/docs/books/tutorial/uiswing/components/border.html

public slss() {

JFrame frame = new JFrame();

Container cp = frame.getContentPane();

cp.setLayout(null);

TitledBorder border1 = new TitledBorder( "2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007"+

"2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007"+

"2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007"+

"2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007 2006-2007" );

if(cp instanceof JComponent){

((JComponent)cp).setBorder(border1);

}

frame.setSize(1280,775);

frame.setLocationRelativeTo(null);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

}

public static void main(String[] args) {

new slss();

}

}

hello.everyonea at 2007-7-21 22:00:10 > top of Java-index,Java Essentials,Java Programming...
# 18
What the hell are you trying to do, lol?
TuringPesta at 2007-7-21 22:00:10 > top of Java-index,Java Essentials,Java Programming...
# 19
its a thing im making for my high schools time capsule
hello.everyonea at 2007-7-21 22:00:10 > top of Java-index,Java Essentials,Java Programming...
# 20
> now a second issue proberly something easy...my> titled border only fills the top not the sides and> the bottomIt's not supposed to. Do you expect the text to wrap around the entire border? You can't do that with TitledBorder.
hunter9000a at 2007-7-21 22:00:10 > top of Java-index,Java Essentials,Java Programming...
# 21
oh really?
hello.everyonea at 2007-7-21 22:00:10 > top of Java-index,Java Essentials,Java Programming...
# 22
is there any way to do that?
hello.everyonea at 2007-7-21 22:00:10 > top of Java-index,Java Essentials,Java Programming...
# 23
r u there my friend?
hello.everyonea at 2007-7-21 22:00:10 > top of Java-index,Java Essentials,Java Programming...
# 24
No, there's no way to do that with swing classes. There might be a library out there that can do what you want, but I highly doubt it. It may be possible to code it yourself, but it's almost certainly beyond your current skill level (no offense), and would definitely be a pain in the
hunter9000a at 2007-7-21 22:00:10 > top of Java-index,Java Essentials,Java Programming...
# 25
Seriously, its pointless to continue while youre using the wrong code.Try adding 2 borders to the JPanel. With one aligned to the top and the other to the bottom. I dont know if thats possible but give it a try.
TuringPesta at 2007-7-21 22:00:10 > top of Java-index,Java Essentials,Java Programming...
# 26
wil it also do the sides?
hello.everyonea at 2007-7-21 22:00:10 > top of Java-index,Java Essentials,Java Programming...
# 27
im not quite sure how to align the border to top bottom right left
hello.everyonea at 2007-7-21 22:00:10 > top of Java-index,Java Essentials,Java Programming...
# 28
read the tutorial i posted for you.good luck! bye.
TuringPesta at 2007-7-21 22:00:10 > top of Java-index,Java Essentials,Java Programming...
# 29

> im not quite sure how to align the border to top

> bottom right left

You can't. There's only one border for each component. If you call setBorder a second time, you just replace the first border. There's no border that places text on more that one side of the component. I'm running out of ways to say this to you. You need to accept this.

hunter9000a at 2007-7-21 22:00:11 > top of Java-index,Java Essentials,Java Programming...
# 30
Use a Matte borderActually, strike that suggestion.Message was edited by: filestream
filestreama at 2007-7-21 22:00:16 > top of Java-index,Java Essentials,Java Programming...
# 31
so ur saying that there is absolutely to make text go all the way around?
hello.everyonea at 2007-7-21 22:00:16 > top of Java-index,Java Essentials,Java Programming...
# 32
can matte border set text all around?
hello.everyonea at 2007-7-21 22:00:16 > top of Java-index,Java Essentials,Java Programming...
# 33
sorry, strike my suggestion.
filestreama at 2007-7-21 22:00:16 > top of Java-index,Java Essentials,Java Programming...
# 34
oh ok i didnt think it wud work tho since matte is ussually one specicif colour
hello.everyonea at 2007-7-21 22:00:16 > top of Java-index,Java Essentials,Java Programming...
# 35

im reading that site u gave me about titled border

Create a titled border. The string argument specifies the title to be displayed. The optional font and color arguments specify the font and color to be used for the title's text. The border argument specifies the border that should be displayed along with the title. If no border is specified, then a look-and-feel-specific default border is used.

By default, the title straddles the top of its companion border and is left-justified. The optional integer arguments specify the title's position and justification, in that order. TitledBorder defines these possible positions: ABOVE_TOP, TOP (the default), BELOW_TOP, ABOVE_BOTTOM, BOTTOM, and BELOW_BOTTOM. You can specify the justification as LEADING (the default), CENTER, or TRAILING. In locales with Western alphabets LEADING is equivalent to LEFT and TRAILING is equivalent to RIGHT.

hello.everyonea at 2007-7-21 22:00:16 > top of Java-index,Java Essentials,Java Programming...
# 36
Well, one way to do it with Matte is to make your border text a graphic and then pass that into the MatteBorder.Another way to do what you want is to extend AbstractBorder.
filestreama at 2007-7-21 22:00:16 > top of Java-index,Java Essentials,Java Programming...
# 37
lol seems hard
hello.everyonea at 2007-7-21 22:00:16 > top of Java-index,Java Essentials,Java Programming...
# 38
maybe u can help me abit?
hello.everyonea at 2007-7-21 22:00:16 > top of Java-index,Java Essentials,Java Programming...
# 39

and if u cant then i dont really care right about now....but heres another thing

1. when u place a picture into a label and paste it on ur cp, it doesnt compress or stretch that image to fit. so i wanted it at 100,100 when the picture is much bigger?

any idea on how to solve this one?

hello.everyonea at 2007-7-21 22:00:16 > top of Java-index,Java Essentials,Java Programming...
# 40

If you really want to use MatteBorder, (which is the closest you'll get without coding it yourself), create an image that has your text written on it. Use the ImageIcon constructor that takes a filename to load the image, then pass that to the MatteBorder constructor that takes an Icon. It'll be written horizontally all around, but it should be there.

hunter9000a at 2007-7-21 22:00:16 > top of Java-index,Java Essentials,Java Programming...
# 41
yeah i guess that wud work but ill worry about that later. thanks tho...mabye u have some ideas about my new topic question about pictures
hello.everyonea at 2007-7-21 22:00:16 > top of Java-index,Java Essentials,Java Programming...
# 42

Just because I was curious about if this would really work or not, I created a quick test, you can try it out and see if it works for you.

package sandbox;

public class NewJFrame extends javax.swing.JFrame {

public NewJFrame() {

initComponents();

}

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">

private void initComponents() {

jPanel1 = new javax.swing.JPanel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBorder(new javax.swing.border.MatteBorder(new javax.swing.ImageIcon("D:\\Profiles\\HDAVIS\\My Documents\\My Pictures\\test.PNG")));

getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

pack();

}// </editor-fold>

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new NewJFrame().setVisible(true);

}

});

}

// Variables declaration - do not modify

private javax.swing.JPanel jPanel1;

// End of variables declaration

}

hunter9000a at 2007-7-21 22:00:16 > top of Java-index,Java Essentials,Java Programming...
# 43
did it work for u?
hello.everyonea at 2007-7-21 22:00:16 > top of Java-index,Java Essentials,Java Programming...
# 44
> did it work for u?Yeah, I used a 10*10 png, and it tiled it around the border. Did it work for you?
hunter9000a at 2007-7-21 22:00:16 > top of Java-index,Java Essentials,Java Programming...
# 45
i havent tried it b/c i dont have the 2006-2007 pic
hello.everyonea at 2007-7-21 22:00:21 > top of Java-index,Java Essentials,Java Programming...
# 46
can u send me the one u got of the pic so i can try it myself
hello.everyonea at 2007-7-21 22:00:21 > top of Java-index,Java Essentials,Java Programming...
# 47
Just open Paint, scribble on it and save it somewhere on your hard drive. That's all I did. If you're not on windows, use whatever the equivalent graphics editor is.
hunter9000a at 2007-7-21 22:00:21 > top of Java-index,Java Essentials,Java Programming...
# 48
oh ic ill go do that
hello.everyonea at 2007-7-21 22:00:21 > top of Java-index,Java Essentials,Java Programming...
# 49
ok i did a pic but how can i make the matte border into my program without making a whole new program?
hello.everyonea at 2007-7-21 22:00:21 > top of Java-index,Java Essentials,Java Programming...
# 50
where did everyone go?
hello.everyonea at 2007-7-21 22:00:21 > top of Java-index,Java Essentials,Java Programming...