|
-
Sep 29th, 2004, 04:53 PM
#1
Thread Starter
Dazed Member
Shifting components in a JToolBar?
I created a JToolBar that i eventually want to use in an application. When i hook the JToolBar into one of my apps the Buttons dont seem to line up right. I want to shift them over but nothing seems to work. Any ides on how i can do this?
Code:
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ToolBar extends JToolBar{
JButton redo;
JButton refresh;
JButton help;
public ToolBar(){
setFloatable(false);
redo = new JButton();
redo.setIcon(new ImageIcon("C:" +
File.separator + "JavaLFGraphicsRepository" + File.separator + "toolbarButtonGraphics"
+ File.separator + "general" + File.separator + "Redo24.gif"));
redo.setToolTipText("Update Database");
refresh = new JButton();
refresh.setIcon(new ImageIcon("C:" +
File.separator + "JavaLFGraphicsRepository" + File.separator + "toolbarButtonGraphics"
+ File.separator + "general" + File.separator + "Refresh.24.gif"));
refresh.setToolTipText("Refresh Table");
help = new JButton();
help.setIcon(new ImageIcon("C:" +
File.separator + "JavaLFGraphicsRepository" + File.separator + "toolbarButtonGraphics"
+ File.separator + "general" + File.separator + "Help24.gif"));
help.setToolTipText("Help");
//add(Box.createVerticalStrut(1)); // Pushes buttons all the way over to the right.
//addSeparator(new Dimension(0,100)); // does nothing
add(help);
add(redo);
add(refresh);
}
}
Last edited by Dilenger4; Sep 30th, 2004 at 05:43 PM.
-
Sep 29th, 2004, 08:47 PM
#2
Fanatic Member
dunno if this helps but got no prob with this code
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class sample extends JFrame{
public sample(){
setTitle("Sample");
setSize(400,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().add(new ToolBar(),BorderLayout.NORTH);
}
// ToolBar
class ToolBar extends JToolBar{
JButton redo=new JButton("Redo",new ImageIcon("left.gif")),
refresh=new JButton("Refresh",new ImageIcon("middle.gif")),
help=new JButton("Help",new ImageIcon("right.gif"));
public ToolBar(){
setFloatable(false);
redo.setVerticalTextPosition(AbstractButton.BOTTOM);
redo.setHorizontalTextPosition(AbstractButton.CENTER);
redo.setToolTipText("Update Database");
refresh.setVerticalTextPosition(AbstractButton.BOTTOM);
refresh.setHorizontalTextPosition(AbstractButton.CENTER);
refresh.setToolTipText("Refresh Table");
help.setVerticalTextPosition(AbstractButton.BOTTOM);
help.setHorizontalTextPosition(AbstractButton.CENTER);
help.setToolTipText("Help");
add(redo);
add(refresh);
add(help);
}
}
public static void main(String[] args){
new sample().show();
}
}
-
Sep 29th, 2004, 11:19 PM
#3
Thread Starter
Dazed Member
Thanks
Now how would i shift them over?
-
Sep 29th, 2004, 11:22 PM
#4
Fanatic Member
Pardon my ignorance but what is Shift? 
edit: you mean, invert the order?
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class sample extends JFrame{
public sample(){
setTitle("Sample");
setSize(400,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().add(new ToolBar(),BorderLayout.NORTH);
}
// ToolBar
class ToolBar extends JToolBar{
JButton redo=new JButton("Redo",new ImageIcon("left.gif")),
refresh=new JButton("Refresh",new ImageIcon("middle.gif")),
help=new JButton("Help",new ImageIcon("right.gif"));
public ToolBar(){
setFloatable(false);
redo.setVerticalTextPosition(AbstractButton.BOTTOM);
redo.setHorizontalTextPosition(AbstractButton.CENTER);
redo.setToolTipText("Update Database");
refresh.setVerticalTextPosition(AbstractButton.BOTTOM);
refresh.setHorizontalTextPosition(AbstractButton.CENTER);
refresh.setToolTipText("Refresh Table");
help.setVerticalTextPosition(AbstractButton.BOTTOM);
help.setHorizontalTextPosition(AbstractButton.CENTER);
help.setToolTipText("Help");
//add(redo);
//add(refresh);
//add(help);
add(help);
add(refresh);
add(redo);
}
}
public static void main(String[] args){
new sample().show();
}
}
Works fine but dunno if this is what you mean?
Last edited by brown monkey; Sep 29th, 2004 at 11:29 PM.
-
Sep 29th, 2004, 11:35 PM
#5
Thread Starter
Dazed Member
You seem perplexed. Shift - Move to the right
-
Sep 29th, 2004, 11:40 PM
#6
Thread Starter
Dazed Member
Notice the two commented lines of code in my previous post. Either one dosen't do the trick. I used the value of one because all other values pushed the buttons all the way over to the right of the JToolBar.
The other line didnt work either. The height i dont need so 0 should be fine. For the width now matter what value i pass it does nothing to move the buttons.
Code:
add(Box.createVerticalStrut(1)); // Pushes buttons all the way over to the right.
addSeparator(new Dimension(0,100)); // does nothing
-
Sep 30th, 2004, 01:07 AM
#7
-
Sep 30th, 2004, 05:40 PM
#8
Thread Starter
Dazed Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|