Adding Component above all other components
My initial problem is to put the panel (which is created as a result of a click on a button) above all components that have been added to the GBLTablePanel. I've written the following sample that demonstrates my problem
package test;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
public class GBLTablePanel extends JPanel {
private final GridBagLayout layout;
private final GridBagConstraints gbc;
public GBLTablePanel() {
layout = new GridBagLayout();
gbc = new GridBagConstraints();
setLayout(layout);
JTable table = new JTable();
table.setModel(new DefaultTableModel(new Object[][] {
{ "aaaaaaaaaaaaaaa", 3, "a", null }, { "adasda", 10, "b", null },
{ "aaaaaaaaaaaaaaa", 3, "a", null }, { "adasda", 10, "b", null },
{ "aaaaaaaaaaaaaaa", 3, "a", null }, { "adasda", 10, "b", null },
{ "aaaaaaaaaaaaaaa", 3, "a", null }, { "adasda", 10, "b", null },
{ "assssss", 55, "c", null }, { "asdafasfa", 44, "d", null } },
new String[] { "Title 1", "Title 2", "Title 3", "Title 4" }));
JScrollPane scrollPane = new JScrollPane(table);
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
layout.setConstraints(scrollPane, gbc);
add(scrollPane);
JButton showPanelBtn = new JButton(new AbstractAction("Show panel") {
@Override
public void actionPerformed(ActionEvent e) {
/* When this button is clicked I want that panel to appear on the top (above all components of the GBLTablePanel ) */
JPanel panel = new JPanel();
panel.add(new JLabel("This must be on the top of JTable"));
panel.setSize(panel.getSize().width, 30);
panel.setPreferredSize(new Dimension(panel.getPreferredSize().width, 30));
layout.setConstraints(panel, gbc);
gbc.gridy = 0;
GBLTablePanel.this.add(panel, 0);
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.gridy = 1;
layout.setConstraints(scrollPane, gbc);
add(showPanelBtn);
public static void main(String[] args) {
JFrame f = new JFrame("Test");
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
/* Construct table managed by GridBagLayout */
GBLTablePanel panel = new GBLTablePanel();
f.add(panel);
f.pack();
f.setVisible(true);
}I hope the example is not too confusing, honestly I'm not sure what do I try next to fix my problem. The panel simply does not show up :(
Here is an example that might help you with using GridBagLayout:
package table;
* TableInGridbaglayout.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TableInGridbaglayout extends JFrame {
private JButton btShowPanel;
private JPanel panel;
private JTable table;
private boolean show;
public TableInGridbaglayout() {
super("TableInGridbaglayout");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(400, 300);
setLocationRelativeTo(null);
panel = new JPanel();
table = new JTable(4, 4);
btShowPanel = new JButton("Show Panel");
panel.setBorder(BorderFactory.createTitledBorder("Panel on top of table"));
panel.setVisible(false);
getContentPane().setLayout(new GridBagLayout());
GridBagConstraints gridBagConstraints;
//panel:
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridheight = 3;
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 0.3;
getContentPane().add(panel, gridBagConstraints);
//table:
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.fill = GridBagConstraints.BOTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 1.0;
getContentPane().add(new JScrollPane(table), gridBagConstraints);
//button:
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
gridBagConstraints.anchor = GridBagConstraints.SOUTH;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.weighty = 0.1;
getContentPane().add(btShowPanel, gridBagConstraints);
btShowPanel.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent evt) {
show = !show;
btShowPanel.setText(show ? "Hide Panel" : "Show Panel");
panel.setVisible(show);
public static void main(final String args[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
new TableInGridbaglayout().setVisible(true);
}
Similar Messages
-
PApplet/component is always above all other components except...
Hi,
I am working with java and a program off shoot of Java called Processing. Processing aids in the creation of java and it integrates itself into a swing component by extending into a PApplet(Processing�s version of an applet) which a JFrame sees as a component.
Example:
newJFrame.add(PApplet); <--- works perfectly except�
The integration of java/swing and processing in an application works very well except for one problem. The Processing class (PApplet) draws to the screen and when I put it into a JFrame, JPanel, JInternalFrame, etc � the graphics are always above all other component except the JMenuBar. I found a fix for the JMenuBar to be this line of code �JPopupMenu.setDefaultLightWeightPopupEnabled(false);� I guess it tells the popup manager of the JMenuBar to not setDefaultLightWeightPopupEnabled which in turn, allows the JMenuItems to popup above the PApplet.
Is there a way to force the PApplet/component to follow the rules of all other components? (setComponentZOrder, setLayer, etc�) It works for the JMenuBar so I feel it should be able to work for all other components � is there a way?
Thanks,
4dplaneThanks for the info; I believe you hit the nail on the head. Processing is open source so I looked in the PApplet class and it extends Applet, so this means processing is awt based.
Thanks,
4dplane -
Adding a panel over other components in the main mxml application
Hi,
I've created a main mxml file that contains,among other things, a button, and another mxml that contains a panel with some options. I want to be able to add that panel to the main mxml OVER all other components in the main mxml file with a mouse click on the button in that main mxml. How can this be done, please help ?Hi mesanarapscallion,
Can you please post the sample code you are working...
Do you want to show the panel component on all the thing above in the main.mxml file...Do you have all the other things positioned at the same position..?
Thanks,
Bhasker Chari -
I've installed CS6 and web Premium on a Mac running 10.9.5, and Dreamweaver,Flash and Illustrator wont launch. All other components work normally. In Activity monitor it says Adobe switchboard failed to respond. Can anyone help solve this issue?
Release: 4/25/2012
http://support.amd.com/us/gpudownload/windows/Pages/radeonmob_win7-64.aspx -
Can iChat be pinned above all other windows
would like to keep iChat chats pinned to desktop and kept above all other windows. Hate having to look for the window when I have multiple other things going on and if someone wants me vs others in the chat the bouncing icon doesn't do it for me. Thanks for the help
Raman,
This does not sound like an xMII issue but rather your computing environment.
-Sam -
Ideas to display which component drives the other components in the canvas
I have 4 components in my canvas and I would like to learn some ideas from gurus on what are the best ways to display which component drives (drills down) the other components in the dashboard. Any info would be appreciated.
Hi,
There is no such rule on which component should drive other in Xcelsius. It all depends upon the data that you are using. Always a component with summarized data should drive a component with granular data. For eg: If you are showing Total sales in a country using Column chart and want to drilldown to the percentage of sales in each region of a particular country , you can use pie chart to show it. Here Column chart drives Pie chart and u can show this in other way also.
Hope it helps!
Thanks,
Arun US -
Custom component composed of other components
Hello.
I have a form (long, but simple) that is reused a few times across my applicaition. It would be great if I could package it as a JSF component. But I see no obvious way to create an UIComponent composed of other UIComponents.
Are UIComponents really meant to be written from scrach, each parsing it's own request parameters and outputting raw html? Am I missing something?
Thanks.Thanks for the quick reply, but I'm still stuck...
How do I go about writing a composite custom
component? Instanciating all sub components and
delegating encoding and decoding to each? That's the road I try to take first.
- Construct a SMALL test-bed application to develop your component.
- consider implementing the naming container interface if you add components as children
- consider acquiring "JSF in Action" from Kito Mann, it's the book with most samples for component building
- announce "absences" to your family. It takes longer than you think beforehand ;-)
- If your servlet-container starts up in less than 10 seconds it's better...
I'm afraid to be asking too much, but does anyone
know where can I find an example of this? I'm
currently browsinng the MyFaces code, but so far
whithout much luck....Well the myfaces code is the second best source after JSF in action and then there are a few tutorials on the net... time to surf to google and http://www.jsftutorials.net/
hope this helps
Alexander -
Creating GUI component that includes other components
Hello, I need to create an UNIVERSAL FORM (panel) consisting of several textboxes and labels. These textboxes and labels will be defined in XML. I want it as a GUI JavaBean. It should be made from a panel with some layout and it should consist other components. Here are my questions:
1) What class to derive from? JPanel?
2) Well, when I override a GUI Swing component I must implement a paint method but this is a bit strange. I just want to set up the textboxes -- I do not need any special painting. A question appears -- is JavaBean technology good for this situation? Is there any better solution?I mean why this doesn`t work:
public class Uniform extends JComponent implements
Serializable {
private String xmlContent;
private int type;
private JPanel panel;
public Uniform() {
panel = new JPanel(new GridLayout(1,2));
panel.add(new JTextField("A"));
panel.add(new JTextField("B"));
public void paint(Graphics g) {
panel.paint(g);
}Is it a good solution? How would you solve the
problem?
Thanks for your ideas.If you mean by 'dont' work' that your text boxes and panel doesn't appear, then it's because you're missing this line in your constructor:
public Uniform() {
this.add (panel, BorderLayout.CENTER);
}Regards,
Devyn -
Referencing component parameters from other components
I have a training application that uses a variety of
components, including a browser that, as a parameter, takes a movie
clip instance and will move it around when the scroll bars and the
browser are used. I also have transparent buttons that on
mouse-over turn slightly opaque so the user can see very obviously
that they're mousing over something. I also have popups that, as a
parameter, take the button instance name, and comes up when the
button is moused over. When the button is clicked, is passes a
parameter to an isCorrect variable (true or false) that is used by
the popup to determine what color to turn the text (green if
isCorrect == true, red else). The popup then puts up some
additional text, to steer the user right. The problem with this is
that all the wrong answers usually say the same thing, and only to
correct one says something different, and often there are well over
50 popups per page, meaning each must be changed manually. And if,
when reviewed, the text is determined to have to change, then it
takes far too long to change it! So, as a solution, I put a
parameter on my browser component called Popup Text with a variable
name _browserPopupText. I need to be able to refrence it from the
popup component. I am able to refrence the button currently because
the instance name is entered as a parameter.
By way of extra information, the popup instances are are
placed inside of the movieClip that is moved around by the browser,
so it isn't on the same layer. I've tried using
this._parent._parent, which resolves properly (this being the
button, this._parent refrencing the movieClip object,
this._parent._parent being a relative way to say _root (since I
have multiple _levels that need to move around on each other a
lot), which resolves to the _level# that the clip and browser are
on). however, I don't know how to refrence the browser without
giving it an instance name, which I'd rather not force users to do
(this training building app will be used by more-or-less computer
illiterate people to build training Flash apps, and so I want to
make it as uninvolved as possible).
So, if there is a way to NOT have to give the browser an
instance name and still refrence parameters in it from the popup, i
would greatly appreciate hearing it.
JAk. I found myself a work-around. In the browser component,
during the init() function initiallizing the browser, i simply
added the following line of code:
_global.browserPopupText = _browserPopupText;
This works just fine. Then, i just refrence the _global
variable. Also, I moved the isCertify from the buttons to the
browser, so that I don't have to change every button from
"isCertify = false" to "isCertify = true". Now All these things
that used to be in literally hundreds of components has been moved
to a handful of them--just the browser. Anyway, there's my
work-around. I'm still open for a better way to do it. -
Can we upgrade a WAS to basis700 while all other components stay 640?
We have this "strange" requirement for some reason. We never did upgarde on only one component.
Could you tell whether this will not cause any problem?
Thanks!The background is as follows:
We want to upgrade a production VIRSA to GRC5.3. Per note 1133173 "Upgrade to SAP BASIS 700 with VIRSANH 530_700", seems only BASIS and ABA need to be upgraded to 700 for our VIRSA
upgrade purpose.
We want to minimize the change on the production, that's it.
Your advices are very helpful. Thanks! -
XMII apllication window raises above all other windows
>My xMII application refreshes every 30 seconds.
>I have to open apllication such as Outlook express along with xMII apllication.As soon as xMII apllication refreshes it takes me to xMII application window from the already open Outlook express window.
>Is this a browser property?
>I want to avoid opening of xMII apllication as soon as it refreshes.
>Can I use a function "alwaysraised" to avoid this situation?Raman,
This does not sound like an xMII issue but rather your computing environment.
-Sam -
Menus appearing underneath other components
I am having a problem making my menus appear on top when they 'pop up'. I know this is a problem with mixing heavyweight and lightweight components, and I have been trying to force the menus to be heavyweight but to no avail.
I have been trying to set the menus to be heavyweight by calling this method after the menu has been instantiated:
[menuname].getPopupComponent().lightWeightPopupEnabled(false);
Here is an image showing my problem:
http://www.inf.brad.ac.uk/~jpcatter/menus.jpg
Edited by: JonCat on Jul 26, 2008 8:47 AMIt is not a mix of swing and awt. The browser component is the mozswing MozillaPanel component, and it is this that is being drawn on top of my menus, as can be seen from the screenshot that I posted. Another thought I had was that the browser component is the last to be drawn, as it is added to the tab control once all other components are drawn. Could it be the Z ordering of components causing the overlap, or is it strictly a heavy / light weight issue?
Here is a link to the mozswing homepage for anyone who is interested:
http://confluence.concord.org/display/MZSW/Home -
Putting Components on top of other components
Hi,
I need some help with the following subject:
from the super-class i need to place a component on top of all other components (or paint something on top of these), but when i add the component it shows below all other components.
How can I make this work?sorry, but this was a little to essential.
1. how does the paint method of the VXComponent look like?
2. where and how do you add the other components, which are drawn on top of your component?
3. actually you seem to use no LayoutManager?
- I never did that but I'd guess it causes the container to draw the components just in the (reverse?) order in which they where added.
if this is the case something like this should help:
add(vx, 0),
or
add(vx, getComponentCount()-1);
regards
Spieler -
Adding Component to JFileChooser excludes other components
I want to add a JComboBox component to a JFileChooser but when I do, the default components that are supposed to be in that space don't show up.
For example, in the JFileChooser, there are several components (like the accept and cancel buttons) in the SOUTH area of the BorderLayout. When I add a custom combobox like so:
JFileChooser fc = new JFileChooser();
cb = new JComboBox();
fc.add(cb, BorderLayout.SOUTH);
dialogResult = fc.showSaveDialog();the combobox I added is the ONLY component which shows up in the SOUTH area.
I have tried adding the combobox as an accessory, but it always shows up to the right of the file browser window. If I can control where the accessory shows up, that would be fine, but I don't see any way to do that.
I don't understand why the other components wouldn't show up?
Thanks in advance for any help.fc.add(cb, BorderLayout.SOUTH);
This line replaces the components that were
previously in that space - read the tutorial on
BorderLayout. In addition, this code is very brittle
and you can have no guarantee that it will work under
different look-and-feels and in future versions of
JDK, since you're making some far-fetching
assumptions on the internal implementation of the
file chooser dialog.Thanks very much for the help!
Fundamentally, i did not realize that in BorderLayout you may only set ONE component to each area (NORTH, SOUTH, CENTER, etc.).
Once I understood that, I grabbed the component at the bottom of the filechooser and placed it in a JPanel with the components I wanted to Add to the bottom.
This worked perfectly!
I am uncertain, however, about why you say the code is "brittle" and what you mean by making assumptions regarding the internal implementation.
In any case, thanks again for your help!
For anyone else who is interested, here is what the code looks like
JFileChooser fc = new JFileChooser();
JComboBox cb = new JComboBox();
JPanel panel = new JPanel();
BoxLayout box = new BoxLayout(panel,BoxLayout.Y_AXIS);
BorderLayout layout = (BorderLayout) fc.getLayout();
panel.setLayout(box);
Component comp = layout.getLayoutComponent(BorderLayout.SOUTH);
panel.add(comp);
panel.add(cb);
fc.add(panel,BorderLayout.SOUTH); -
Component always displays "under" other components......
Hi there,
I have a component derived from a "panel" - I'm adding it to the applet but it always displays itself "under" the other components in the applet, never above (which is where I want it).
I've tried adding it last and adding it first - doesn't make any difference. When I add the component I set it to "setVisible(false)" and "setVisible(true)" when the user clicks a button. I'm a bit confused as to why its underneath everything else!
Any ideas?
Thanks.I am using my own paint methods indeed - I mean I'm calling "super" and then rendering the component - or calling "super" in a container component and rendering other stuff on the container afterwards.
But this is all working on the version you see on the website - the one I'm working on is broken.
btw. I'm using a "Panel" (derives from Container, its a lightweight thingy, nout to do with Schwing etc.).
Maybe you are looking for
-
IPod not recognized by iTunes..related posts doesn't help me
I got a new iPod which I am trying to connect to my machine. I am using USB 2.0 to connect it to my machine. Note that my machine doesn't have Firewire. Windows recognizes it, but my iTunes gives me error: "The software required to communicate with i
-
No organization data for service products
Hi, I create a CRM service order with a service product. Now there is a message, that the product in sales organization and distribution channel is not scheduled. Our service products in general don't have organization data, cause they occur from r/3
-
Dear Users Last week I had a clean install of Windows 7 64bit on my M305D-S4830 laptop. I've used this OS on this machine before, and it worked fine. After installing Win7, the device manager showed 2 unknown devices. First I've installed the O2 mult
-
I've been using iDVD to burn videos for awhile now. This time around it is either force closing while burning or near the end it gives a error while multiplexing and will not continue. Is there something I can do to fix this? Or another program I can
-
hi i currently have software iOs 4.3.3. and want to instalo icloud on my iPad 2. i understand That to do this i need to update to versión 5.1.1. but from what i understand i need a laptop to do this. i dont have another computer so how do i go about