Results 1 to 3 of 3
  1. #1
    phraxos is offline Member
    Join Date
    Oct 2010
    Posts
    1
    Rep Power
    0

    Default TitledBorder in Swing

    Hello all,

    I have a problem creating proper TitledBorder to JPopupMenu.

    The result is a border that is very thick, and white, while in all the examples I found on the net the thickness is 1 - simple line.

    The TitledBorder class in java sais that it uses the look&feel to determine the border, but I want it to be thickness 1.

    How should I do it?

    Thanks!

    The code:

    Class MenuPopup extends JPopupMenu{
    ...
    LinedBorder border = new LinedBorder(Color.WHITE, 1);
    //creates border with thickness 1.
    border = new TitledBorder(border, "some title);
    setBorder(border);
    //The result is a border with thikcness 5 or more.
    ...
    }

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    mhm..and which look&feel do you use? :confused:
    Java Code:
    The code:
    
    Class MenuPopup extends JPopupMenu{
    ...
    LinedBorder border = new LinedBorder(Color.WHITE, 1); 
    //creates border with thickness 1.
    border = new TitledBorder(border, "some title);
    setBorder(border); 
    //The result is a border with thikcness 5 or more. 
    ...
    }
    that can not be your code, because there are many many errors.

    what about this snippet? the same issue?
    Java Code:
    	public static void main(String[] args) throws Exception {
    		SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				JFrame frame = new JFrame();
    				JPanel panel = new JPanel();
    				panel.setComponentPopupMenu(new JPopupMenu() {
    					{
    						add(new JLabel("hello popup"));
    						setBorder(new TitledBorder(new LineBorder(Color.WHITE, 1), "title"));
    					}
    				});
    				frame.add(panel);
    				frame.setSize(500, 500);
    				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    				frame.setLocationRelativeTo(null);
    				frame.setVisible(true);
    			}
    		});
    	}

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    I think that at this point you'll have to post some more code. I recommend that you create and post the smallest program possible that is compilable, runnable, demonstrates your problem, and has no extraneous code not related to the problem, an SSCCE . Please see the link for details on how to create one of these because trust me, if your SSCCE is compliant with the specs, you'll likely get a very helpful answer from someone here quickly.

    Also, when posting code here, please use code tags so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?

    To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

    Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:

    Java Code:
    [code]
      // your code goes here
      // notice how the top and bottom tags are different
    [/code]
    Best of luck and welcome to the java-forums.org!

Similar Threads

  1. Swing
    By tmotse in forum AWT / Swing
    Replies: 0
    Last Post: 03-31-2010, 11:18 AM
  2. swing.jar
    By krrishnak in forum AWT / Swing
    Replies: 2
    Last Post: 04-05-2009, 06:29 AM
  3. What is next to Swing
    By javaplus in forum AWT / Swing
    Replies: 1
    Last Post: 01-13-2008, 11:16 PM
  4. where is the swing jar?
    By katie in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 11:58 PM
  5. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 08:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •