UIManager.put("InternalFrame.activeTitleBackground", new ColorUIResource(new Color(207,255,247)));
UIManager.put("InternalFrame.inactiveTitleBackground", new ColorUIResource(new Color(207,255,247)));
JDesktopPane baTabbedPane = new JDesktopPane();
JInternalFrame iframe = new JInternalFrame("Cheapest To Deliver",true,true,true,true);
iframe.setSize(400,150);
baTabbedPane.add(iframe);
why is my Internal Frame's title background not set on startup?
I've tried setting it on the overall JFrame init but made no difference (By contrast I could change other JFrame ui component look n feel such as MenuItem.background in this location so I thought it might have been because the JInternalFrame was not a top-level component i.e. under a tabbed pane, that maybe it needed changing at some other point, but where?)
Any tips on the correct place to call UIManager.put() for JInternalFrame?
got it eventually - the call to put() works fine after JInternalFrame creation but I did make it before I added the component to a container. I then still had to set it's UI:
JInternalFrame iframe = new JInternalFrame("blah",true,true,true,true);
UIManager.put("InternalFrame.activeTitleBackground", new ColorUIResource(new Color(248,250,175)));
UIManager.put("InternalFrame.inactiveTitleBackground", new ColorUIResource(new Color(248,250,175)));
javax.swing.plaf.basic.BasicInternalFrameUI ui =
new javax.swing.plaf.basic.BasicInternalFrameUI(iframe);
iframe.setUI(ui);
I think you need to make all calls to UIManager.put before you create any Swing components.
Related
I'm using NetBeans and I made basic layout with jPanel in the middle of it. Now I would like to add Webcam panel in this jPanel.
Here's example how to get frames from webcam and display it in new window. It's working fine.
Webcam webcam = Webcam.getDefault();
webcam.setViewSize(WebcamResolution.VGA.getSize());
WebcamPanel panel = new WebcamPanel(webcam);
panel.setFPSDisplayed(true);
panel.setDisplayDebugInfo(true);
panel.setImageSizeDisplayed(true);
panel.setMirrored(true);
JFrame window = new JFrame("Test webcam panel");
window.add(panel);
window.setResizable(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);
But when I tried to display it in my existing jPanel it's not working. Webcam screen is not visible. Here's my code:
Webcam webcam = Webcam.getDefault();
webcam.setViewSize(WebcamResolution.VGA.getSize());
WebcamPanel panel = new WebcamPanel(webcam);
panel.setFPSDisplayed(true);
panel.setDisplayDebugInfo(true);
panel.setImageSizeDisplayed(true);
panel.setMirrored(true);
jPanel5.add(panel);
jPanel5.setVisible(true);
I call all of this in my main class constructor. Just after other netbeans componenst are loaded. When I add example it's working good but then my main layout is loaded and webcam screen in another window. I would like to get it in the same window.
I have seen other topics about adding image to jPanel but it's not working with capturing movie from webcam.
Thanks for help.
But when I tried to display it in my existing jPanel it's not working.
When you add components to a visible GUI the basic code is:
panel.add(...);
panel.revalidate(); // invoke the layout manager
panel.repaint(); // paint components
All component have a default size of (0, 0) when created so there is nothing to paint. You need to invoke the layout manager so the component is given a size/location.
I changed a little my application and now in the middle of main windows is JTabbedPane and I found a solution to my problem. Instead of making Tabs using NetBeans window designer I made it with code.
I made empty JTabbedPane in Netbeans and then add this to code:
final JPanel jPanelCamera = new JPanel();
jTabbedPane1.addTab("Camera", jPanelCamera);
Webcam webcam = Webcam.getDefault();
webcam.setViewSize(WebcamResolution.VGA.getSize());
WebcamPanel webcamPanel = new WebcamPanel(webcam);
webcamPanel.setFPSDisplayed(true);
webcamPanel.setDisplayDebugInfo(true);
webcamPanel.setImageSizeDisplayed(true);
webcamPanel.setMirrored(true);
jPanelCamera.add(webcamPanel);
jPanelCamera.getParent().revalidate();
System.out.println("Camera OK");
I have no idea why earlier when I made component using NetBeans designer it was't working but now it's working good. I think if someone would add this not to JTabbedPane, but to JPanel should also make this panel with code. Not with Netbeans designer and then it should work.
I am trying to create a JPanel to display when a user clicks a button within my main JFrame. In Netbeans I first used the wizard to add a new JPanel to my project, I then used the GUI creator to fill in all the content. I am not trying to display the JPanel with the following code
private void m_jbShowSelAccResultsActionPerformed(java.awt.event.ActionEvent evt)
{
Account selAcc = getSelectedAccount();
if(selAcc != null)
{
AccountView accPanel = new AccountView(Account.getDeepCopy(selAcc));
accPanel.setVisible(true);
}
else
ShowMessage("Please select an account to view");
}
But nothing happens, no error is thrown and the JPanel is not shown. So I then changed the JPanel to a JFrame (Netbeans didn't complain). When I try again with the same code I receive the error GroupLayout can only be used with one Container at a time.
How can I display my JPanel/JFrame?
To change views within a Swing GUI, use a CardLayout as this is a much more robust and reliable way to do this.
Don't try to blindly "change a JPanel to a JFrame". It looks like you're just guessing here.
GroupLayout can't be reused as the error message is telling you. Likely this error comes from the point above. If you avoid trying to make a JFrame out of a JPanel, the error message will likely go away. As an aside, GroupLayout is not easily used manually, especially if you're trying to add components to an already rendered GUI.
So for instance, if your program had a JPanel say called cardHolderPanel, that used a CardLayout, this held by a variable say called cardLayout, and you've already added a "card" JPanel to this holder for accounts, say called accPanel, and if the accPanel had a method to set its currently displayed account, say setAccount(Accoint a), you could easily swap views by calling the CardLayout show(...) method, something like:
private void m_jbShowSelAccResultsActionPerformed(java.awt.event.ActionEvent evt) {
Account selAcc = getSelectedAccount();
if(selAcc != null) {
accPanel.setAccount(Account.getDeepCopy(selAcc));
cardLayout.show(cardHolderPanel, "Account View");
}
else {
showErrorMessage("Please select an account to view");
}
}
In my main class I initially start out by creating the java frame. Later I create a new object from another class entitled 'keybinding' and pass it the JFrame. It then applies the action maps for certain keys to the root pane of the JFrame.
I was previously writing this application in the educational IDE BlueJ where this code worked fine. But I'm in the process of moving it to regular IDE, in this case JDeveloper. All the code works apart from the this keybinding.
With the below code, using JDev, calling getRootPane() returns null.
Stage.java
jf = new JFrame("The Title");
jf.setSize(800,600);
//etc
Keybinding keys = new Keybinding(this);
Keybinding.java
KeyStroke pressLeft = KeyStroke.getKeyStroke("LEFT");
stage.jf.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
.put(pressLeft, "pressLeft");
The parameter to the KeyBinding class should just be
new KeyBinding(jf);
Then the code in the KeyBinding class can access the frame as follows:
public KeyBinding(JFrame frame)
{
JRootPane rootPane = frame.getRootPane();
rootPane.getInputMap(...)
}
I'm trying to make a simple pie chart appear on a jpanel in netbeans with JFreeChart and got this:
public void createPieChart()
{
DefaultPieDataset myPie = new DefaultPieDataset();
myPie.setValue("Apples",new Integer(12));
myPie.setValue("Oranges",new Integer(23));
myPie.setValue("Mangos",new Integer(7));
myPie.setValue("Pears",new Integer(22));
JFreeChart myChart = ChartFactory.createPieChart3D("Damo's Fruit Sales", myPie,true,true,true);
PiePlot3D pie3D = (PiePlot3D)myChart.getPlot();
ChartPanel myPanel = new ChartPanel(myChart);
lowerMain_PNL.removeAll();
lowerMain_PNL.add(myPanel,BorderLayout.CENTER);
lowerMain_PNL.revalidate();
}
I get no compiler errors and when it runs the window appears with the button, but when I press the button my pie chart doesn't appear. Anyone know what I could be missing?
Check the layout manager of lowerMain_PNL. Netbeans form designer uses GroupLayout by default, so unless you changed it, that's what you got. Adding to a container using GroupLayout at run time is tricky, especially if the component contains more than one subcomponent (And requires adding components to the layout, instead of using the usual add() methods).
Change it to BorderLayout instead, since you are using BorderLayout constraints.
Currently I have a very basic file viewer working as follows :
- in JOptionPane I browse for files, and set some variables to display (colors, line connecting etc)
- previous windows loads a frame with drawn points
alt text http://img190.imageshack.us/img190/4443/104bu.jpg
Code :
http://paste.pocoo.org/show/220066/
Now I'd like to throw it into one window, with JMenu for selecting files and changing display parameters. How to get started ? Should I rewrite everything to JDialog ?
alt text http://img684.imageshack.us/img684/5264/lab10db.jpg
If you want the JOPtionPane as a child of the main JFrame, then add it as a child. Of course it will then cover your dots. Hence you will have to not draw your dots directly in the content pane of the main JFrame, but rather in a new JPanel that you have also added to the JFRame's content pane. Let me know if I've understood the question whatsoever.
Here's some code for how I see the setup (I'm leaving the layout problem out of this, partly because it depends on what you want to see):
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setSize(new Dimension(400,400));
frame.getContentPane().add(new JOptionPane());
JPanel canvasForDots = new JPanel();
frame.getContentPane().add(canvasForDots);
You might also like to look at How to Use Tool Bars and How to Use Menus. ImageApp is a typical implementation that associates menu items with the corresponding Action instances.
private class ClearAction extends AbstractAction {…}
private class ImageOpenAction extends AbstractAction {}
private Action openAction = new ImageOpenAction("Open");
private Action clearAction = new ClearAction("Clear");
…
JMenu menu = new JMenu("File");
menu.add(new JMenuItem(openAction));
menu.add(new JMenuItem(clearAction));
This related example adds the file chooser directly to the main frame. Here's a more elaborate example of connecting lines and shapes using the same principles.