Extending JPanel to contain a JRootPane - problems with scroll panes
I am trying to write a JPanel subclass that contains a JRootPane, similar to the way that JFrame contains a JRootPane. The reason that I am doing this is that I would like to be able to intercept mouse events using the JGlassPane facility, but adding the glasspane to the JFrame is problematic since it then intercepts mouse events over all components in the JFrame, including the menu bar. It seems simpler to me to have the JRootPane owned by a JPanel, to give me better control over intercepting events. I've got an implementation working with the JFrame case, but have had to handle many small "gotchas", and at least one more exists. I'm hoping to simplify things by moving away from this way of doing things.
I wrote a straightforward RootPanePanel class that extends JPanel and implements RootPaneContainer, delegating all of the add methods to the JRootPane's content pane. Here's the constructor for RootPanePanel:
public RootPanePanel (LayoutManager layout) {
rootPane = new JRootPane ();
rootPane.setOpaque(true);
rootPane.getContentPane().setLayout(layout);
super.add (rootPane);
}RootPanePanel also delegates calls like getContentPane/setContentPane to the JRootPane.
To test my implementation, I wrote a main method that looks like the following:
public static void main (String[] args) {
SwingUtilities.invokeLater(new Runnable () {
public void run () {
try {
JEditorPane editorPane = new JEditorPane ("http://www.archives.gov/exhibits/charters/print_friendly.html?page=declaration_transcript_content.html&title=NARA%20%7C%20The%20Declaration%20of%20Independence%3A%20A%20Transcription");
JScrollPane scrollPane = new JScrollPane (editorPane);
JFrame frame = new JFrame ("Test RootPanePanel");
RootPanePanel panel = new RootPanePanel ();
panel.add(scrollPane);
frame.add(panel, BorderLayout.CENTER);
scrollPane.setPreferredSize(new Dimension(800, 600));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize (640, 480);
frame.pack ();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
});Note that I'm not actually using JEditorPane in my application, but it is the simplest component that displays the problem I'm encountering.
When this code runs, it is fine, as long as the JFrame is big enough to display the scrollbars for the JScrollPane. If the JFrame is made small enough, the scrollbars are not displayed.
If I instead add the JScrollPane to the JFrame directly, it behaves as you would expect.
Is this a problem of mixing heavyweight and lightweight components? It doesn't seem like it should be; in both cases the JScrollPane is handling the same client component, the JEditorPane.
Any suggestions/ideas are welcome!
Here's the full RootPanePanel class in case people want to try it out
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.LayoutManager;
import java.io.IOException;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;
import javax.swing.RootPaneContainer;
import javax.swing.SwingUtilities;
public class RootPanePanel extends JPanel implements RootPaneContainer {
private JRootPane rootPane;
public RootPanePanel () {
this (new BorderLayout());
public RootPanePanel (LayoutManager layout) {
rootPane = new JRootPane ();
rootPane.setOpaque(true);
rootPane.getContentPane().setLayout(layout);
super.add (rootPane);
public Container getContentPane() {
return rootPane.getContentPane();
public Component getGlassPane() {
return rootPane.getGlassPane();
public JLayeredPane getLayeredPane() {
return rootPane.getLayeredPane();
public void setContentPane(Container arg0) {
rootPane.setContentPane(arg0);
public void setGlassPane(Component arg0) {
rootPane.setGlassPane(arg0);
public void setLayeredPane(JLayeredPane arg0) {
rootPane.setLayeredPane(arg0);
@Override
protected void addImpl(Component comp, Object constraints, int index)
if (comp == rootPane) {
super.addImpl(comp, constraints, index);
else {
getContentPane().add(comp, constraints, index);
@Override
public Component add(Component comp, int index) {
return rootPane.getContentPane().add(comp, index);
@Override
public void add(Component comp, Object constraints, int index) {
rootPane.getContentPane().add(comp, constraints, index);
@Override
public void add(Component comp, Object constraints) {
rootPane.getContentPane().add(comp, constraints);
@Override
public Component add(Component comp) {
return rootPane.getContentPane().add(comp);
@Override
public Component add(String name, Component comp) {
return rootPane.getContentPane().add(name, comp);
public static void main (String[] args) {
SwingUtilities.invokeLater(new Runnable () {
public void run () {
try {
JEditorPane editorPane = new JEditorPane ("http://www.archives.gov/exhibits/charters/print_friendly.html?page=declaration_transcript_content.html&title=NARA%20%7C%20The%20Declaration%20of%20Independence%3A%20A%20Transcription");
JScrollPane scrollPane = new JScrollPane (editorPane);
JFrame frame = new JFrame ("Test RootPanePanel");
RootPanePanel panel = new RootPanePanel ();
panel.add(scrollPane);
frame.add(panel, BorderLayout.CENTER);
scrollPane.setPreferredSize(new Dimension(800, 600));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize (640, 480);
frame.pack ();
frame.setVisible(true);
} catch (HeadlessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
public JRootPane getRootPane() {
return rootPane;
}
Similar Messages
-
Problem with scrolling a panel containing an image
I am having a problem adding scrolling capabilities to a tabbed panel containing pages containing an image. In my program, I have a class called ImagePanel that extends JPanel and contains an image read from a file. In another class, I create a tabbed panel and add to it ImagePanels.
The problem I'm facing is that the pages added to my tabbed panel contain scroll bars, but these scroll bars are not scrollable (i.e. I cannot use the bars the scroll and see the missing parts of the image).
Any help on this manner is highly appreciated.
The code is shown below:
JTabbedPane m_pathwayTabbedPane = new JTabbedPane();
ImageIcon overviewImageIcon = IconLoader.readImageIcon(pathway.gif);
ImagePanel overviewPanel = new ImagePanel(overviewImageIcon.getImage());
JScrollPane graphcrollPane = new JScrollPane(overviewPanel,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
m_pathwayTabbedPane.addTab(StringManager.OVERVIEW, graphcrollPane);import java.awt.*;
import java.io.*;
import java.net.*;
import javax.imageio.ImageIO;
import javax.swing.*;
public class ScrollingImages
public static void main(String[] args)
String[] fileNames = {
"images/bclynx.jpg", "images/mtngoat.jpg", "images/redfox.jpg"
JPanel panel = new JPanel(new GridBagLayout());
panel.setBackground(Color.black);
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(5,5,5,5);
gbc.gridwidth = gbc.REMAINDER;
for(int j = 0; j < fileNames.length; j++)
panel.add(new ImageComponent(fileNames[j]), gbc);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new JScrollPane(panel));
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
class ImageComponent extends JPanel
Image image;
public ImageComponent(String fileName)
loadImage(fileName);
setBackground(Color.black);
protected void paintComponent(Graphics g)
super.paintComponent(g);
int w = getWidth();
int h = getHeight();
int imageWidth = image.getWidth(this);
int imageHeight = image.getHeight(this);
int x = (w - imageWidth)/2;
int y = (h - imageHeight)/2;
g.drawImage(image, x, y, this);
* For the JScrollPane which will inquire about our size
* which it needs to properly set its scrollbars.
public Dimension getPreferredSize()
return new Dimension(image.getWidth(this), image.getHeight(this));
private void loadImage(String fileName)
try
URL url = getClass().getResource(fileName);
image = ImageIO.read(url);
catch(MalformedURLException mue)
System.out.println(mue.getMessage());
catch(IOException ioe)
System.out.println(ioe.getMessage());
} -
Parallax Scrolling: Problems with scroll wheel
Hi,I'm syue
I learn parallax effect from this video.
It helps me a lot ,but I have a problem with scroll wheel
Everything looks nice on my computer.
But when I make a test on different computers.It will show something like this...
https://docs.google.com/file/d/0B-eo1Bu6k3N-cEw2c3dyWEpfNDA/preview
I don't know how to explain the situation so I make this video.
I also chick my code and it shows me everything is fine.
I don't know how to solve this problem
Can you give me some advice?
Best regards. :-DI know many people who have 30 gig and no wheel problem. I have an 80 gig and no problem. Finding your warranty (or buying the extended warranty) would be useful.
Good luck.
Kid -
In the last few days, I've encountered a problem with scrolling with my up & down keys. The up & down keys seem to, now function as Home & End keys. MyPage Up & Page Down keys seem to do nothing. What is wrong?
Hit the '''F7''' key, you probably have Caret browsing turned on.
http://kb.mozillazine.org/Accessibility.browsewithcaret -
New to Applets: Problems wiht writing to files and with scroll panes.
Hi, I've recently graduated from university and so I have limited experience in java programming and I'm having some trouble with JApplets (this is the first time I've made one). I'm trying to make a simple program that will allow users to pick one of a few background images from a list (a list of jpanels within a scroll pane) then at the click of a button will output a CSS with the background tag set to the image location. This is for use on a microsoft sharepoint site where each user has a My-Sit area which I want to be customizable.
So far I've been creating this program as an application rather than a JApplet and just having another class that extends the JApplet Class which then displays the JFrame from the GUI Class. This initially didnt work because I was trying to add a window to a container so I kept programming it as an application until I got it working before trying to convert it to a JApplet. I solved the previous problem by changing my GUI class to extend JPanel instead of JFrame and it now displays correctly but with a coupe of issues.
Firstly the applet will not create/write to the CSS file. I read that applets couldnt read/write to the users file system but they could to their own. The file I wish to write to is kept on the same machine as the applet so I'm not sure why this isn't working.
Secondly the scroll panel is no longer working properly. This worked fine when I was still running the program as an application when the GUI still extended JFrame instead of JPanel (incidentally the program no longer runs as an application in this state) but now the scroll bar does not appear. This is a problem since I want the applet to remain the same size on the page even if I decide to add more backgrounds to the list. I tried setting the applet height/width to smaller values in the html file to see if the scroll bar would appear if the area was smaller than the GUI should be, but this just meant the bottom off the applet was cut off.
Could anyone offer any suggestion as to why these thigns arnt working and how to fix them? If necessary I can post my source code here. Thanks in advance.Ok, well my program is made up of 4 classes, I hope this isnt too much to be posting. If any explaination is needed then I'll post that next. Theres lots of print lines scattered aroudn due to me trying to fix this and theres some stuff commented out from when the program used to be an application isntead of an applet.
GUI Class, this was the main class until I made a JApplet Class
public class AppletGUI extends JPanel{
*GUI Components*
//JFrames
JFrame mainGUIFrame = new JFrame();
JFrame changeBackgroundFrame = new JFrame();
//JPanels (Sub-panels are indented)
JPanel changeBackgroundJP = new JPanel(new BorderLayout());
JPanel changeBackgroundBottomJP = new JPanel(new GridLayout(1,2));
JPanel backgroundJP = new JPanel(new GridLayout(1,2));
JPanel selectBackground = new JPanel(new GridLayout(1,2));
//Jbuttons
JButton changeBackgroundJB = new JButton("Change Background");
JButton defaultStyleJB = new JButton("Reset Style");
//JLabels
JLabel changeBackgroundJL = new JLabel("Choose a Background from the Menu");
JLabel backgroundJL = new JLabel();
//JScrollPane
JScrollPane backgroundList = new JScrollPane();
JPanel backgroundListPanel = new JPanel(new GridLayout());
//Action Listeners
ButtonListener bttnLstnr = new ButtonListener();
//Controllers
CSSGenerator cssGenerator = new CSSGenerator();
Backgrounds backgroundsController = new Backgrounds();
backgroundMouseListener bgMouseListener = new backgroundMouseListener();
//Flags
Component selectedComponent = null;
*Colour Changer*
//this method is used to change the colour of a selected JP
//selected JPs have their background darkered and when a
//different JP is selected the previously seleced JP has its
//colour changed back to it's original.
public void changeColour(JPanel theJPanel, boolean isDarker){
//set selected JP to a different colour
Color tempColor = theJPanel.getBackground();
if(isDarker){
tempColor = tempColor.darker();
else{
tempColor = tempColor.brighter();
theJPanel.setBackground(tempColor);
//also find any sub-JPs and change their colour to match
int j = theJPanel.getComponents().length;
for(int i = 0; i < j; i++){
String componentType = theJPanel.getComponent(i).getClass().getSimpleName();
if(componentType.equals("JPanel")){
theJPanel.getComponent(i).setBackground(tempColor);
*Populating the GUI*
//backgroundList.add();
//Populating the Backgrounds List
*Set Component Size Method*
public void setComponentSize(Component component, int width, int height){
Dimension tempSize = new Dimension(width, height);
component.setSize(tempSize);
component.setMinimumSize(tempSize);
component.setPreferredSize(tempSize);
component.setMaximumSize(tempSize);
*Constructor*
public AppletGUI() {
//REMOVED CODE
//AppletGUI.setDefaultLookAndFeelDecorated(true);
//Component Sizes
//setComponentSize
//Adding Action Listeners to Components
System.out.println("adding actions listeners to components");
changeBackgroundJB.addActionListener(bttnLstnr);
defaultStyleJB.addActionListener(bttnLstnr);
//Populating the Change Background Menu
System.out.println("Populating the window");
backgroundsController.populateBackgroundsData();
backgroundsController.populateBackgroundsList();
//loops to add background panels to the JSP
ArrayList<JPanel> tempBackgroundsList = new ArrayList<JPanel>();
JPanel tempBGJP = new JPanel();
tempBackgroundsList = backgroundsController.getBackgroundsList();
int j = tempBackgroundsList.size();
JPanel backgroundListPanel = new JPanel(new GridLayout(j,1));
for(int i = 0; i < j; i++){
tempBGJP = tempBackgroundsList.get(i);
System.out.println("Adding to the JSP: " + tempBGJP.getName());
//Add Mouse Listener
tempBGJP.addMouseListener(bgMouseListener);
backgroundListPanel.add(tempBGJP, i);
//set viewpoing
backgroundList.setViewportView(backgroundListPanel);
/*TESTING
System.out.println("\n\n TESTING!\n Printing Content of SCROLL PANE \n");
j = tempBackgroundsList.size();
for(int i = 0; i < j; i++){
System.out.println(backgroundList.getComponent(i).getName());
changeBackgroundJP.add(changeBackgroundJL, BorderLayout.NORTH);
changeBackgroundJP.add(backgroundList, BorderLayout.CENTER);
//changeBackgroundJP.add(tempBGJP, BorderLayout.CENTER);
changeBackgroundJP.add(changeBackgroundBottomJP, BorderLayout.SOUTH);
changeBackgroundBottomJP.add(changeBackgroundJB);
changeBackgroundBottomJP.add(defaultStyleJB);
System.out.println("Finsihed populating");
//REMOVED CODE
//adding the Background Menu to the GUI and settign the GUI options
//AppletGUI.setDefaultLookAndFeelDecorated(true);
//this.setResizable(true);
//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocation(500,500);
this.setSize(400,300);
this.add(changeBackgroundJP);
//REMOVED CODE
*Main Method*
public static void main(String[] args){
System.out.println("Creating GUI");
AppletGUI theGUI = new AppletGUI();
theGUI.setVisible(true);
System.out.println("GUI Displayed");
*Button Listener Inner Class*
public class ButtonListener implements ActionListener{
//check which button is clicked
public void actionPerformed(ActionEvent event) {
AbstractButton theButton = (AbstractButton)event.getSource();
//Default Style Button
if(theButton == defaultStyleJB){
System.out.println("Default Style Button Clicked!");
//Change Background Button
if(theButton == changeBackgroundJB){
System.out.println("Change Background Button Clicked!");
String backgroundURL = cssGenerator.getBackground();
if(backgroundURL != ""){
cssGenerator.setBackgroundChanged(true);
cssGenerator.setBackground(backgroundURL);
cssGenerator.outputCSSFile();
System.out.println("Backgroudn Changed, CSS File Written");
else{
System.out.println("No Background Selected");
*Mouse Listener Inner Class*
public class backgroundMouseListener implements MouseListener{
public void mouseClicked(MouseEvent e){
//get component
JPanel tempBackgroundJP = new JPanel();
tempBackgroundJP = (JPanel)e.getComponent();
System.out.println("Background Panel Clicked");
//change component colour
if(selectedComponent == null){
selectedComponent = tempBackgroundJP;
else{
changeColour((JPanel)selectedComponent, false);
selectedComponent = tempBackgroundJP;
changeColour((JPanel)selectedComponent, true);
//set background URL
cssGenerator.setBackground(tempBackgroundJP.getName());
public void mousePressed(MouseEvent e){
public void mouseReleased(MouseEvent e){
public void mouseEntered(MouseEvent e){
public void mouseExited(MouseEvent e){
}JApplet Class, this is what I plugged the GUI into after I made the change from Application to JApplet.
public class AppletTest extends JApplet{
public void init() {
System.out.println("Creating GUI");
AppletGUI theGUI = new AppletGUI();
theGUI.setVisible(true);
Container content = getContentPane();
content.setBackground(Color.white);
content.setLayout(new FlowLayout());
content.add(theGUI);
AppletGUI theGUI = new AppletGUI();
theGUI.setVisible(true);
setContentPane(theGUI);
System.out.println("GUI Displayed");
public static void main(String[] args){
AppletTest at = new AppletTest();
at.init();
at.start();
}The CSS Generator Class. This exists because once I have the basic program working I intend to expand upon it and add multiple tabs to the GUI, each one allowing the user to change different style options. Each style option to be changed will be changed wit ha different method in this class.
public class CSSGenerator {
//Variables
String background = "";
ArrayList<String> backgroundCSS;
//Flags
boolean backgroundChanged = false;
//Sets and Gets
//For Variables
public void setBackground(String theBackground){
background = theBackground;
public String getBackground(){
return background;
//For Flags
public void setBackgroundChanged(boolean isBackgroundChanged){
backgroundChanged = isBackgroundChanged;
public boolean getBackgroundChanged(){
return backgroundChanged;
//background generator
public ArrayList<String> backgroundGenerator(String backgroundURL){
//get the URL for the background
backgroundURL = background;
//creat a new array list of strings
ArrayList<String> backgroundCSS = new ArrayList<String>();
//add the strings for the background options to the array list
backgroundCSS.add("body");
backgroundCSS.add("{");
backgroundCSS.add("background-image: url(" + backgroundURL + ");");
backgroundCSS.add("background-color: #ff0000");
backgroundCSS.add("}");
return backgroundCSS;
//Write CSS to File
public void outputCSSFile(){
try{
//Create CSS file
System.out.print("creating file");
FileWriter cssWriter = new FileWriter("C:/Documents and Settings/Gwilym/My Documents/Applet Data/CustomStyle.css");
System.out.print("file created");
System.out.print("creating buffered writer");
BufferedWriter out = new BufferedWriter(cssWriter);
System.out.print("buffered writer created");
//check which settings have been changed
//check background flag
if(getBackgroundChanged() == true){
System.out.print("retrieving arraylist");
ArrayList<String> tempBGOptions = backgroundGenerator(getBackground());
System.out.print("arraylist retrieved");
int j = tempBGOptions.size();
for(int i = 0; i < j ; i++){
System.out.print("writing to the file");
out.write(tempBGOptions.get(i));
out.newLine();
System.out.print("written to the file");
out.close();
}catch (Exception e){//Catch exception if any
System.out.println("Error: Failed to write CSS file");
/** Creates a new instance of CSSGenerator */
public CSSGenerator() {
}The Backgrounds Class. This class exists because I didnt want there to just be a hardcoded lsit of backgrounds, I wanted it to be possible to add new ones to the list without simply lettign users upload their own images (since the intended users are kids and this sharepoint site is used for educational purposes, I dont want them uplaoded inapropraite backgrounds) but I do want the site admin to be able to add more images to the list. for this reason the backgrounds are taken from a list in a text file that will be stored in the same location as the applet, the file specifies the background name, where it is stored, and where a thumbnail image is stored.
public class Backgrounds {
//Array Lists
private ArrayList<JPanel> backgroundsList;
private ArrayList<String> backgroundsData;
//Set And Get Methods
public ArrayList getBackgroundsList(){
return backgroundsList;
//ArrayList Population Methods
public void populateBackgroundsData(){
//decalre the input streams and create a new fiel hat points to the BackgroundsData file
File backgroundsDataFile = new File("C:/Documents and Settings/Gwilym/My Documents/Applet Data/BackgroundsData.txt");
FileInputStream backgroundsFIS = null;
BufferedInputStream backgroundsBIS = null;
DataInputStream backgroundsDIS = null;
try {
backgroundsFIS = new FileInputStream(backgroundsDataFile);
backgroundsBIS = new BufferedInputStream(backgroundsFIS);
backgroundsDIS = new DataInputStream(backgroundsBIS);
backgroundsData = new ArrayList<String>();
String inputtedData = null;
//loops until it reaches the end of the file
while (backgroundsDIS.available() != 0) {
//reads in the data to be stored in an array list
inputtedData = backgroundsDIS.readLine();
backgroundsData.add(inputtedData);
//TESTING
System.out.println("\n\nTESTING: populateBackgroundsData()");
int j = backgroundsData.size();
for(int i = 0; i < j; i++){
System.out.println("Index " + i + " = " + backgroundsData.get(i));
System.out.println("\n\n");
//close all stremas
backgroundsFIS.close();
backgroundsBIS.close();
backgroundsDIS.close();
} catch (FileNotFoundException e) {
System.out.println("Error: File Not Found");
} catch (IOException e) {
System.out.println("Error: IO Exception Thrown");
public void populateBackgroundsList(){
backgroundsList = new ArrayList<JPanel>();
int j = backgroundsData.size();
System.out.println("number of backgrounds = " + j);
backgroundsList = new ArrayList<JPanel>();
for(int i = 0; i < j; i++){
String tempBackgroundData = backgroundsData.get(i);
JPanel backgroundJP = new JPanel(new GridLayout(1,2));
JLabel backgroundNameJL = new JLabel();
JLabel backgroundIconJL = new JLabel();
//split the string string and egt the background name and URL
String[] splitBGData = tempBackgroundData.split(",");
String backgroundName = splitBGData[0];
String backgroundURL = splitBGData[1];
String backgroundIcon = splitBGData[2];
System.out.println("\nbackgroundName = " + backgroundName);
System.out.println("\nbackgroundURL = " + backgroundURL);
System.out.println("\nbackgroundIcon = " + backgroundIcon + "\n");
backgroundNameJL.setText(backgroundName);
backgroundIconJL.setIcon(new javax.swing.ImageIcon(backgroundIcon));
backgroundJP.add(backgroundNameJL);
backgroundJP.add(backgroundIconJL);
backgroundJP.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
//Name the JP as the background URL so it can be found
//May be useful sicne the data file may need to contain 3 fields in future
//this is incase the preview image (icon) is different from the acctual background
//most liekly in the case of more complex ppictures rather then repeating patterns
backgroundJP.setName(backgroundURL);
//Add the JP to the Array List
backgroundsList.add(backgroundJP);
//TESTING
System.out.println("\n\nTESTING: populateBackgroundsList()");
j = backgroundsList.size();
for(int i = 0; i < j; i++){
System.out.println("Index " + i + " = " + backgroundsList.get(i));
System.out.println("\n\n");
}So thats my program so far, if theres anythign that needs clarifying then please jsut ask. Thank you very much for the help! -
hi,
if I have to add three different toolbars in same content pane.
If I add these, each one of them gets overwrite over another. and only last one toolbar gets visible. please help. Also, I need the toolbar to keep top most when i dock them.shamail says - "I guess you didnt read the message carefully"
late4ever says = "u can't add more than 1 toolbar on top"
Did either of you bother to take the time to read the tutorial on "Using Layout Managers". A JToolBar is simply a component. Multiple components can be added to a container. By default the content pane uses a BorderLayout which only accepts 5 components (Center, North, South, East, West) which is why when you keep adding components to the same area you can only see the last one.
When you create a JPanel, by default it uses a FlowLayout. When you add components they get added to the right of the previous component, which was why I gave you the sample code.
I thought my previous answer was straight forward so I only included a piece of code. Here is a complete program you can run:
import javax.swing.*;
public class MultipleToolBars extends JFrame
public MultipleToolBars(String strName)
this.setTitle(strName);
JPanel jp1 = new JPanel();
JToolBar jtb1 = new JToolBar("tool1");
JToolBar jtb2 = new JToolBar("tool2");
JToolBar jtb3 = new JToolBar("tool3");
JButton jb1 = new JButton("JB1");
JButton jb2 = new JButton("JB2");
JButton jb3 = new JButton("JB3");
JButton jb4 = new JButton("TOOL1");
JButton jb5 = new JButton("TOOL2");
JButton jb6 = new JButton("TOOL3");
JButton jb7 = new JButton("BUTTON1");
JButton jb8 = new JButton("BUTTON1");
JButton jb9 = new JButton("BUTTON2");
jtb1.setFloatable(true);
jtb2.setFloatable(true);
jtb3.setFloatable(true);
jtb1.add(jb1);
jtb1.add(jb2);
jtb1.add(jb3);
jtb2.add(jb4);
jtb2.add(jb5);
jtb2.add(jb6);
jtb3.add(jb7);
jtb3.add(jb8);
jtb3.add(jb9);
jp1.add(jtb1);
jp1.add(jtb2);
jp1.add(jtb3);
getContentPane().add(jp1);
public static void main(String[] args)
MultipleToolBars mtb = new MultipleToolBars("test");
mtb.setSize(600, 75);
mtb.setVisible( true ); -
Problem with scroll tab layout in JtabbedPane
Pls. if anyone know this, help me
I have a problem, my scroll tab layout policy does not working when I set it to UI.
import javax.swing.*;
import javax.swing.plaf.basic.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
public class Components_Area extends JFrame{
JTabbedPane tab = new JTabbedPane(JTabbedPane.TOP,JTabbedPane.SCROLL_TAB_LAYOUT);
JLabel l[] = new JLabel[5];
public Components_Area() {
tab.setUI(new TestPlaf());
tab.addTab("Untitled",l[0]);
tab.addTab("Untitled",l[1]);
tab.addTab("Untitled",l[2]);
tab.addTab("Untitled",l[3]);
tab.addTab("Untitled",l[4]);
getContentPane().add(tab);
public static void main(String args []) {
Components_Area frame = new Components_Area();
frame.setSize(200,200);
frame.show();
static class TestPlaf extends BasicTabbedPaneUI {
protected LayoutManager createLayoutManager() {
return new TestPlafLayout();
protected Insets getTabInsets(int tabPlacement,int tabIndex) {
Insets defaultInsets = (Insets)super.getTabInsets(tabPlacement,tabIndex).clone();
defaultInsets.right += 50;
defaultInsets.top += 2;
return defaultInsets;
class TestPlafLayout extends TabbedPaneLayout {
//a list of our close buttons
java.util.ArrayList closeButtons = new java.util.ArrayList();
public void layoutContainer(Container parent) {
super.layoutContainer(parent);
//ensure that there are at least as many close buttons as tabs
while(tabPane.getTabCount() > closeButtons.size()) {
closeButtons.add(new CloseButton(closeButtons.size()));
tabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
Rectangle rect = new Rectangle();
int i;
for(i = 0; i < tabPane.getTabCount();i++) {
rect = getTabBounds(i,rect);
JButton closeButton = (JButton)closeButtons.get(i);
//shift the close button 3 down from the top of the pane and 20 to the left
closeButton.setLocation(rect.x+rect.width-20,rect.y+4);
closeButton.setSize(15,15);
tabPane.add(closeButton);
for(;i < closeButtons.size();i++) {
//remove any extra close buttons
tabPane.remove((JButton)closeButtons.get(i));
// implement UIResource so that when we add this button to the
// tabbedpane, it doesn't try to make a tab for it!
class CloseButton extends JButton implements javax.swing.plaf.UIResource {
public CloseButton(int index) {
super(new CloseButtonAction(index));
setBorder( BorderFactory.createEmptyBorder() );
setToolTipText("Close this tab");
//remove the typical padding for the button
setMargin(new Insets(0,0,0,0));
addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
setBorder( BorderFactory.createLineBorder(Color.black, 1 ));
public void mouseExited(MouseEvent e) {
setBorder( BorderFactory.createEmptyBorder() );
class CloseButtonAction extends AbstractAction {
int index;
public CloseButtonAction(int index) {
super("x");
this.index = index;
public void actionPerformed(ActionEvent e) {
tabPane.remove(index);
} Message was edited by:
henyoIf someone knows this, help me!
-
Problems with scroll bars in list view
Hello,
I am using Xcelsius 2008 (Build Number 12,2,166). I am still having trouble with scroll bars on my list view control. Other list views in my dashboard seem to be ok. It seems that this list view is not ignoring the blank cells in my excel file. I have gone through many things to correct this problem. I have added a new list view, I have copied other list views that work correctly but still no success. It seems that the "Ignore Blank Cells" property is not working correctly. Does anyone have a solution for this?
Much Thx!Hi Yusufel,
Please check the data whether the cells are really blank or having any space which could not be seen, etc.
With best wishes
BaaRaa. -
Problems with scrolling and Mission Control
I have this problem:
When scrolling down any page, the letters will blur at the top of the screen and not the bottom.
When swiping acrross pages in the launchpad, it occasionaly freezes half way between the two.
When I swipe up with four fingers to access mission control, the screen becomes very sluggish. Swiping back down (or clicking a tab) is even worse, causing slow "laggy" animations.
And this the report from EtreCheck:
Hardware Information:
MacBook Pro (13-inch, Mid 2012)
MacBook Pro - model: MacBookPro9,2
1 2.5 GHz Intel Core i5 CPU: 2 cores
4 GB RAM
Video Information:
Intel HD Graphics 4000 - VRAM: 1024 MB
System Software:
OS X 10.9.2 (13C1021) - Uptime: 0 days 0:3:16
Disk Information:
APPLE HDD HTS545050A7E362 disk0 : (500.11 GB)
EFI (disk0s1) <not mounted>: 209.7 MB
Macintosh HD (disk0s2) / [Startup]: 499.25 GB (309.44 GB free)
HL-DT-ST DVDRW GS41N
USB Information:
Apple Inc. Apple Internal Keyboard / Trackpad
Apple Computer, Inc. IR Receiver
Apple Inc. BRCM20702 Hub
Apple Inc. Bluetooth USB Host Controller
Apple Inc. FaceTime HD Camera (Built-in)
FireWire Information:
Thunderbolt Information:
Apple Inc. thunderbolt_bus
Configuration files:
/etc/hosts - Count: 1
Launch Daemons:
[loaded] com.adobe.fpsaud.plist Support
[loaded] com.microsoft.office.licensing.helper.plist Support
Launch Agents:
[not loaded] com.bose.soundtouch.plist Support
User Launch Agents:
[loaded] com.adobe.ARM.[...].plist Support
[loaded] com.google.keystone.agent.plist Support
[running] com.spotify.webhelper.plist Support
User Login Items:
iTunesHelper
Spotify
BitTorrent
Autodesk 360
Internet Plug-ins:
SharePointBrowserPlugin: Version: 14.0.0 Support
FlashPlayer-10.6: Version: 13.0.0.201 - SDK 10.6 Support
AdobePDFViewer: Version: 10.0.0 Support
Flash Player: Version: 13.0.0.201 - SDK 10.6 Support
QuickTime Plugin: Version: 7.7.3
Default Browser: Version: 537 - SDK 10.9
Audio Plug-ins:
BluetoothAudioPlugIn: Version: 1.0 - SDK 10.9
AirPlay: Version: 2.0 - SDK 10.9
AppleAVBAudio: Version: 203.2 - SDK 10.9
iSightAudio: Version: 7.7.3 - SDK 10.9
iTunes Plug-ins:
Quartz Composer Visualizer: Version: 1.4 - SDK 10.9
3rd Party Preference Panes:
Flash Player Support
Time Machine:
Time Machine not configured!
Top Processes by CPU:
2% WindowServer
2% SoundTouch music server
0% fontd
0% BitTorrent
0% mds
Top Processes by Memory:
90 MB mds_stores
86 MB Safari
78 MB Spotify
57 MB Spotify Helper
49 MB ocspd
Virtual Memory Information:
1.83 GB Free RAM
1.44 GB Active RAM
190 MB Inactive RAM
558 MB Wired RAM
303 MB Page-ins
0 B Page-outsI have this problem:
When scrolling down any page, the letters will blur at the top of the screen and not the bottom.
When swiping acrross pages in the launchpad, it occasionaly freezes half way between the two.
When I swipe up with four fingers to access mission control, the screen becomes very sluggish. Swiping back down (or clicking a tab) is even worse, causing slow "laggy" animations.
And this the report from EtreCheck:
Hardware Information:
MacBook Pro (13-inch, Mid 2012)
MacBook Pro - model: MacBookPro9,2
1 2.5 GHz Intel Core i5 CPU: 2 cores
4 GB RAM
Video Information:
Intel HD Graphics 4000 - VRAM: 1024 MB
System Software:
OS X 10.9.2 (13C1021) - Uptime: 0 days 0:3:16
Disk Information:
APPLE HDD HTS545050A7E362 disk0 : (500.11 GB)
EFI (disk0s1) <not mounted>: 209.7 MB
Macintosh HD (disk0s2) / [Startup]: 499.25 GB (309.44 GB free)
HL-DT-ST DVDRW GS41N
USB Information:
Apple Inc. Apple Internal Keyboard / Trackpad
Apple Computer, Inc. IR Receiver
Apple Inc. BRCM20702 Hub
Apple Inc. Bluetooth USB Host Controller
Apple Inc. FaceTime HD Camera (Built-in)
FireWire Information:
Thunderbolt Information:
Apple Inc. thunderbolt_bus
Configuration files:
/etc/hosts - Count: 1
Launch Daemons:
[loaded] com.adobe.fpsaud.plist Support
[loaded] com.microsoft.office.licensing.helper.plist Support
Launch Agents:
[not loaded] com.bose.soundtouch.plist Support
User Launch Agents:
[loaded] com.adobe.ARM.[...].plist Support
[loaded] com.google.keystone.agent.plist Support
[running] com.spotify.webhelper.plist Support
User Login Items:
iTunesHelper
Spotify
BitTorrent
Autodesk 360
Internet Plug-ins:
SharePointBrowserPlugin: Version: 14.0.0 Support
FlashPlayer-10.6: Version: 13.0.0.201 - SDK 10.6 Support
AdobePDFViewer: Version: 10.0.0 Support
Flash Player: Version: 13.0.0.201 - SDK 10.6 Support
QuickTime Plugin: Version: 7.7.3
Default Browser: Version: 537 - SDK 10.9
Audio Plug-ins:
BluetoothAudioPlugIn: Version: 1.0 - SDK 10.9
AirPlay: Version: 2.0 - SDK 10.9
AppleAVBAudio: Version: 203.2 - SDK 10.9
iSightAudio: Version: 7.7.3 - SDK 10.9
iTunes Plug-ins:
Quartz Composer Visualizer: Version: 1.4 - SDK 10.9
3rd Party Preference Panes:
Flash Player Support
Time Machine:
Time Machine not configured!
Top Processes by CPU:
2% WindowServer
2% SoundTouch music server
0% fontd
0% BitTorrent
0% mds
Top Processes by Memory:
90 MB mds_stores
86 MB Safari
78 MB Spotify
57 MB Spotify Helper
49 MB ocspd
Virtual Memory Information:
1.83 GB Free RAM
1.44 GB Active RAM
190 MB Inactive RAM
558 MB Wired RAM
303 MB Page-ins
0 B Page-outs -
Interlace problem with fast pans, camera moves... any advice?
Hello: I have a video project, edited in FCP (from SD DVCAM tape source). I exported as a standard 4:3 Quicktime movie, and then encoded as H264 video using the multipass 3ivx codec in Cleaner.
I now get a blurred horizontal line on camera pans. The blur appears as a broken line on the lower third of the picture.
Should I not tick the "Adaptive" box?
I have tried using the de-interlace Eliminate Top Field and the Interlace Auto settings. In both cases I ticked the adaptive box. In both cases I still get a blurred broken line in the lower third area of the video on camera pans.
I tried a third experiment using DVFilmMaker. I set it up to de-interlace only on movement, and to blur horizontal lines on Motion (thinking this might help to at least give a more natural look to the picture break-up I was already getting).
Alas, no improvement.
Yes, if I had a time-machine and extra bucks I would have shot Progressive... but I didn't... so I'm trying to get the best out of what I have.
Any thoughts... anyone?
Thanks
A
Message was edited by: Adrian Smith4Thanks for the info. Just for the record, I have tried all these things too in Compressor, QTPro, Cleaner and DVFilmMaker. I get the same problem with all (a blurred line on fast camera pans)
My preference for Cleaner (and it's only my opinion) is that it has a more intuitive user interface for correcting gamma, color, image size, bit-rate, without having to search or go to multiple menus. You also see the video as it encodes and visually check any problems with gamma, etc. You can also do a visual before/after check. I guess it's the devil I'm used to.
Thanks for all the info re. alternatives to Cleaner... but it's not really addressing my original (and existing) problem.
Thanks
Message was edited by: Adrian Smith4
Message was edited by: Adrian Smith4 -
Problem with scrolling using my touchpad with the new Firefox update
I just updated Firefox to 9.o.1, I run Windows 7 and I'm using a HP G62 Notebook PC. Ever since I have updated, I can no longer scroll on webpages using my touchpad. If I use an external mouse, I have no problems. I have also not had any problems with other applications, so I assume that this problem is related to the new update. Is there anything that I can do to fix this now, or will I have to wait for the next update?
I just updated Firefox to 9.o.1, I run Windows 7 and I'm using a HP G62 Notebook PC. Ever since I have updated, I can no longer scroll on webpages using my touchpad. If I use an external mouse, I have no problems. I have also not had any problems with other applications, so I assume that this problem is related to the new update. Is there anything that I can do to fix this now, or will I have to wait for the next update?
-
Problems with audio panning.
Am having problems with audio tracks. For example: when capturing a clip where a person is talking, there would be 2 tracks of audio - one a radio mic (Track 1) and another mic (Tack 2)capturing ambient sound. I often delete the ambient track (Track 2) and am left with the the main audio from a radio mic (Track 1).
The problem is when I open up the main audio track (Track 1) and pan the audio track from -1 to 0 or even to +1! It says it has done it but the sound still comes out of the left speaker.
It is a very recent problem that I wonder may be something to do with preferences or settings.
We have had no problems with the speakers at all.
Thanks very much,
GeoffYou have your audio outputs set to 'dual mono', not 'stereo'.... go to:
Sequence>Settings> 'Audio Outputs' tab > then highlight the 'Stereo' button, then click OK...
problem solved... -
Problem with "Scroll to" SVG on Safari Yosemite
Hello,
I have recently released my new portfolio:
http://www.nerisson.fr
We have used some svgs, and "scroll to" on buttons to navigate on my website.
When we click on a button "works" from the homepage or "read more" from the page "Who am I", the "scroll to" have some lag... And the header pop directly with no transition...
Have you an idea to fix it?
(You can view on Chrome or Firefox, to see the right comportment)
PS : We haven't problem with the previous version of safari
Best regards
JimmyClick here and run Adware Medic.
(113799) -
Basically whenever i place an html item in my Muse site or an object I encounter a problem when scrolling down past that object in the preview. I have a horizontal menu bar that sits on the top of my site and whenever I scroll down the html items and objects
cut through my menu. Is there any way to rectify this? - i've tried pinning objects but can't figure it out. Any help would be greatly appreciated.
Thanks,So you have a pinned Menu in the Master page but is being overlayed by the objects in page when you scroll down? If that is the case, select the Menu in the Master, right click on it and Move To Master Foreground.
Thanks,
Vinayak -
Problems with scrolling after mountain lion download.
I just downloaded mountain lion today and ever since the download I am having issues with the scrolling for my magic mouse and trackpad. My problem is when I scroll down on my mouse or trackpad it actually goes up on the page and vice versa. I have seen others have had some scrolling issues but not exactly the same as mine. Just wondering if there is any known fix for this problem? I did the PRAM reset and also the SMC reset and that didn't fix the problem unfortunately.
Look in System Preferences > Trackpad (or mouse) > Scroll & Zoom tab > uncheck Scroll direction: Natural.
The scrolling direction has been changed to a technique where your push the screen up or pull it down, takes a few days to get used to. The swipe directions will also be affected by this change.
Maybe you are looking for
-
Cannot a get JSP page instance from a page being destroyed
We have a J2EE app, using Struts + Tiles (build 1.1-b3), running on Win2KPro, Ora9ias v9.0.3. The application is roles-based, and different users see different versions of the same page based on their role authorizations. Occasionally, when multiple
-
Converting packed signed decimal to either double or string
I have S9(13)V99 -COMP-3 format which I want to convert to either double or a string. Does any one knows how I can do it. I have browsed the net but did not find what I am looking for. If you have any code please post. Thanks in advance,
-
Installer hung -- M$ Office 2011 on my new iMac.
Hello, Totally new Mac newbie here. I am trying to install M$ Office 2011 on my new iMac. The installer process stopped on the "installation" step and said I needed to quit Safari and Firefox before it could continue. I did quit those apps (at leas
-
After "Hello World" - my first adventure in accepting user input
Hey I'm trying to teach myself java and I'm attempting to move on from printing hello world to the screen :) I've written the following: import java.io.*; public class firstapp { int value1, value2, result; public static
-
I'm trying to remove old apps off my phone, and they keep showing up. How do I get rid of them?