Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JPanel with a TitledBorder  RSS feed

 
Smilidon Sapiens
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Folks...
I tried to make a titled border for my JPanel.
The following code doesnt work :
<code>
JPanel mainPanel = new JPanel();
mainPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("A titled border")));
</code>
I get the error :
--------------------Configuration: j2sdk1.4.0 <Default>--------------------
C:\Dokumente und Einstellungen\IVOHMEJ\Eigene Dateien\PrestoMaske.java:28: <identifier> expected
mainPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("A titled border"), BorderFactory.createEmptyBorder(5,5,5,5)));
^
C:\..\testBorder.java:28: package mainPanel does not exist
mainPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("A titled border")));
^
2 errors
other Examples work fine, i cant find the difference! I imported the same packages.
Please help I think it is something simple
Thx a lot!
 
Rajendar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
i tried the Border thing and it worked fine.
also i am not clear with ur question..can u show the code....
mean while,i wrote this Border example.Try this out..
import java.awt.*;
import java.awt.event.*;
import javax.swing .*;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
public class border extends JFrame
{
JPanel compoundpanel,titledpanel;
Container cont;
Border compound,titled,raisedbevel,loweredbevel ;
JTabbedPane pane;
border()
{
cont=getContentPane();
pane=new JTabbedPane();
compoundpanel=new JPanel();
raisedbevel = BorderFactory.createRaisedBevelBorder();
loweredbevel = BorderFactory.createLoweredBevelBorder();
compoundpanel.setBorder(BorderFactory.createCompoundBorder(raisedbevel,loweredbevel));
titledpanel=new JPanel();
titledpanel.setBorder(BorderFactory.createTitledBorder("title"));

pane.addTab("titled",titledpanel);
pane.addTab("compound",compoundpanel);
cont.add(pane,BorderLayout.CENTER);
}

public static void main(String a[])
{
JFrame frame =new border();
frame.setSize(400,400);
frame.setVisible(true);
}
}
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Smilidon.
You tried to create a compund border that contains a title border ONLY.
compound border are borders that contain 2 borders to combine for a special effect like (rasied lowered, titled etched) etc...
just add another border to your compoundborder method and it will work , or use title border alone as Rajendar pointed out.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roy Ben Ami is right, a compound border is used to make a combination of two border styles and you only supplied one.

Smilidon Sapiens and Rajendar, please re-register with a user name that follows the Official JavaRanch User Name Guidelines. Rajendar, user names are required to be in the format "First Name" + space + "Last Name", and Smilidon Sapiens, even though you got the formatting right, user names are also required to not be obviously fake.

Thanks,

-Nate
 
Smilidon Sapiens
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post a code example please... Thanks!
Why is it so important that you know my real name? OK, i will change my nickname, but is this realy my name :-) ?! I like this board, but you have a big problem with your usernames...
Regards Bonkers...
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i just copy pasted your code to here to llok like this:
JPanel mainPanel=new JPanel();
mainPanel.setBorder(BorderFactory.createTitledBorder("A titled border"));
thats it!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Smilidon Sapiens,
Much thought has gone into the user name issue... basically we've (the bartenders, sheriffs, and owner of JavaRanch) that using real (or at least "real-looking") names helps make the site look more "professional", so managers should have less problem with someone getting Java help from a "professional" site, rather than wasting their time on websites getting Java advice from people named "Bunny Girl" and "StUdMuff1n1001". Plus, using a real name tends to cut down on the "flame factor"... most people tend to be nicer to one another when not hiding behind names like "DeathLord2020" and "(\/)45T3R_H4X0R".

Even though real names are preferred, you can choose a user name that is not your actual name, but could be an actual name. Where as "Brian Tenner" is a valid user name, "Smilidon Sapiens" ( or "Adam Baum", "Ben Dover", "Al Ian", or "Phil Erup" ) is not. This has been discussed many times by many different people, and it hasn't been changed yet.

Besides, part of the user agreement (the part where you click "OK" when registering) specifies this...

Your friendly neighborhood bartender,
-Nate
 
Kay Tracid
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for disabling my user... Thanks for giving me the time to change my username...
You like your members, isn't it...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!