Fill space in panel with GridBagLayout
Hello,
I have a class that extends JPanel and uses a GridBagLayout.
I would like the contents of this panel to occupy the whole available space.
However, I don't find how to do it with GridBagLayout (I know this is automatically done with BorderLayout but I want to use GridBagLayout for organizing internal components).
I have this small program to show the problem.
In this example, how could the button fill all the available space with GridBagLayout?
Note that setting GridBagConstraints fill to BOTH doesn't solve the issue.
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.LayoutManager;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TestBlankSpace {
private static int x = 200;
public static void main(String[] args) {
testPanel(new BorderLayout(), BorderLayout.CENTER);
testPanel(new GridBagLayout(), createGridBagConstraints());
private static void testPanel(LayoutManager manager, Object constraints) {
JPanel panel = new JPanel(manager);
JButton button = new JButton("button");
button.setBackground(Color.ORANGE);
panel.setBackground(Color.WHITE);
panel.add(button, constraints);
JFrame window = new JFrame("Test Panels");
window.add(panel);
window.setLocation(x, 200);
window.setSize(400, 300);
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
x += 400;
private static GridBagConstraints createGridBagConstraints() {
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
return c;
}Thank you
Hi,
For better understanding the grid bag layout read this tutorial :
[http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html|http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html]
Olek
Similar Messages
-
How to put Panel with GridBagLayout to top left edge
Morning everybody!
So, i got a small question. When i have a panel with a GridBagLayout, the components are always aligned to the center of the panel... Is there a posibility to align them to the top left edge?
Regards, michaelThanks!
But i solved the problem myself. I just put the panel with the GridBagLayout into on with BorderLayout.
Now it's okay. Maybe this solution is a dirty one, but it works!
I wasn't able to make any changes with anchor. No matter which value, nothing changed....
Regards, Michael -
Pb of resizing panels with GridBagLayout
Hi !
I've got three panels one under each other (A, B and C) and use GridBagLayout as layout.
I'd like to resize only the center one (B) and conserve the height of other ones (A, B).
When I fix the size, the preferred, minimum and maximum sizes to the same number for A and C, it doesn't work.
Has someone got an idea, please :(
delphAre you also setting fill for the constraints on the middle panel to GridBagConstraints.BOTH?
For this requirement you'd be bettter using a BorderLayout though - it does just what you describe (if you use NORTH, CENTER, SOUTH for A, B, C) and its a lot lighter in its footprint. -
How to fill my collapsible panels with dynamic content from PHP scripts?
Hi people,
I'm trying to generate dynamically generated content in a
Spry collapsible panel. Previously I've generated PHP files that as
an output generates a dynamic table with the data I want to show. I
figured it would be possible to use an php include option to
generate this table in a content section of a Spry collapsible
panel. However, when I do this the collapsible panels appear to
join and when panel1 is clicked all tables close instead of only
panel 1 and all tables are put benath each other without putting it
in each seperate panel. But when i replace the file with only the
text "content" it works fine. Do i maybe have to add some kind of
command at the end of my php file to make it look like the
"content"-text or is this not the problem?
I've been looking for the answer now for a couple of weeks on
various forums and nothing seemed to work for me. Can please
somebody help me out?
Greets,
Damian
The code in its non working form:
<head>
<!--Link the CSS style sheet that styles the Collapsible
Panel-->
<link href="SpryAssets/SpryCollapsiblePanel.css"
rel="stylesheet"
type="text/css" />
<!--Link the Spry Collapsible Panel JavaScript
library-->
<script src="SpryAssets/SpryCollapsiblePanel.js"
type="text/javascript"></script>
</head>
<body>
<!--Create the Collapsible Panel widget and assign
classes to each element-->
<div id="CollapsiblePanel1" class="CollapsiblePanel1">
<div class="CollapsiblePanelTab">Tab</div>
<div class="CollapsiblePanelContent"><?php
include('details_books.php');?></div>
</div>
<div id="CollapsiblePanel2" class="CollapsiblePanel2">
<div class="CollapsiblePanelTab">Tab</div>
<div class="CollapsiblePanelContent"><?php
include('details_authors.php');?></div>
</div>
<!--Initialize the Collapsible Panel widget object-->
<script type="text/javascript">
var CollapsiblePanel1 = new
Spry.Widget.CollapsiblePanel("CollapsiblePanel1");
</script>
<script type="text/javascript">
var CollapsiblePanel2 = new
Spry.Widget.CollapsiblePanel("CollapsiblePanel2");
</script>
</body>you need to save the page as a php page (.php) It works
fine -
Creating filling panel with insets without gridbaglayout
Hi,
This is quite a newbie prob but i can't seem to get it right. I want a Panel with two panels. Both with insets. I want the first to only fill horizontally. The second has to fill-up the rest of the panel. Because Boxlayout and Borderlayout don't support insets with layout i tried the gridbaglayout, but i can't get the second panel to fill the remainder of the panel. It stops halfway.
contentPane.add(one,
new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(2, 2, 2, 2), 0, 0));
contentPane.add(two,
new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
GridBagConstraints.BOTH, new Insets(2, 2, 2, 2), 0, 0));
Can anyone tell me how to do this?
Much thanks
Hugo HendriksYou can use:
panel.setBorder(BorderFactory.createEmptyborder(2,2,2,2));
to set insets on a JPanel. I believe Insets is the "old" way of doing borders.
Regards,
Tim -
hello, i changed my mediathek-folder due to space-problems and since then i am not able to fill the iphone (4) with music anymore. also i cant delete music in itunes, which already is on the iphone... HELP!
does anybody know how to solve this problem? thx!If you want to try to clear even more disk space see https://discussions.apple.com/thread/5872318?tstart=0
-
Problem with 'Filling Space' described in Tim's Blog
Dear Experts,
I am using the Invoice Template described in the excellent Blog by Tim Dexter (Anatomy of a Template) to produce my own version. However, I am having problems with the 'Filling Space' described here: http://blogs.oracle.com/xmlpublisher/2007/03/anatomy_of_a_template_ii_heade.html
My template is almost identical to the example, when I import XML data where there is only one record, the Filling Space does not pad out with enough empty rows so that the Total table is not at the bottom of the page, aligned with the watermark that I have. The code in the 'Filling Space' field is as in the Blog:
<?if:not(count($invLines) mod $lpp=0) and ($start+$lpp>count($invLines))?><?for-each:$invLines?><?if:position()<$lpp - (count($invLines) mod $lpp)?>
If the number of records is greater than half a page or more, then the padding is correct. This is even if, say on the third page there is just one record. Therefore, it seems the padding does not work if the number of records are less than half a page in total.
Is this correct and does anyone have a solution - would be greatly appreciated.
Many thanks,
Mark"If the number of records is greater than half a page or more, then the padding is correct. This is even if, say on the third page there is just one record. Therefore, it seems the padding does not work if the number of records are less than half a page in total."
This statement is wrong.
Leave the if conditions logic,
This is how it works,..
xml contains 43 rows...
each page you need 10 rows..
after every 10th rows [using position mod 10 ,] , you put a page break...
if the mod returns greater than 0, that means row filler has to come into effect now.
what is the logic now to have row fillers is , 10 - 3 [position mod 10] , comes to 7... so seven blank rows should be inserted..
this is how , it works...
so the statement, saying, less than half of page, or something, wont come into this :).
http://winrichman.blogspot.com/2008/09/limit-row-per-page.html -
Can I hide the Adobe Reader panel with "Export, Create and Edit PDF and Send and Store Files"? I don't use it and it takes up space
If you just mean, can I close it, sure. In Reader XI click the Tools button to close or reopen it.
-
Filling space with non-visible component?
Is there a better way to fill space to squeeze objects closer together in a gridlayout/flowlayout than simply making gui components and setting their visibility to false?
I thought so too but...
newApplet.java:105: reference to add is ambiguous, both method add(java.awt.PopupMenu) in java.awt.Component and method add(java.awt.Component) in java.awt.Container match
userNamePanel.add(null); -
Displaying custom drawn panels in a panel with FlowLayout vs GridLayout
I am having trouble to display my custom panels(on which I have drawn) in another panel with FlowLayout. When I use this layout only a small part of their top-left corner appears, when using the GridLayout they are displayed as should, all. Why is this? Is there any way around it?
The following is the code:
package diagramillustrator;
import java.awt.*;
import java.util.Vector;
import javax.swing.*;
public class ClassDiagram extends JPanel
//fields
//<editor-fold>
//general info
public String title = "class";
public String name;
public Vector interfaces;
public Vector exceptions;
public String superclass;
public Vector subClasses;
public boolean superClass;
public boolean subClass;
public String dPackage;
public String dExtends;
//variables
public FieldStructure field;
//methods
public MethodStructure constructor;
public MethodStructure metho;
//</editor-fold>
/** Creates a new instance of ClassDiagram */
public ClassDiagram()
super();
super.setSize(132,75);
protected void paintComponent(Graphics g)
setBackground(Color.WHITE);
Graphics2D g2d = (Graphics2D) g;
super.paintComponent(g2d);
g2d.setStroke(new BasicStroke(2f));
g2d.drawRect(1,1,132,25);
g2d.setFont(new Font("arial", Font.BOLD, 12));
g2d.drawString(title, 4,18);
g2d.setColor(Color.LIGHT_GRAY);
g2d.fillRect(1,25,132,25);
g2d.setColor(Color.BLACK);
g2d.drawRect(1,25,132,25);
g2d.setColor(Color.WHITE);
g2d.fillRect(1,51,132,25);
g2d.setColor(Color.BLACK);
g2d.drawRect(1,50,132,25);
public static void main(String[] args)
JFrame f = new JFrame("Testing ClassDiagram");
f.setSize(500,400);
//layout shows it correctly
JPanel panel1 = new JPanel(new GridLayout());
//layout shows it incorrectly
//JPanel panel1 = new JPanel(new FlowLayout());
panel1.setSize(200,200);
ClassDiagram c1 = new ClassDiagram();
ClassDiagram c2 = new ClassDiagram();
ClassDiagram c3 = new ClassDiagram();
panel1.add(c1);
panel1.add(c2);
panel1.add(c3);
f.add(panel1);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.show();
}Here is the main method included in the class(the main method is used for testing here) where the adding etc is done.
public static void main(String[] args)
JFrame f = new JFrame("Testing ClassDiagram");
f.setSize(500,400);
//layout shows it correctly
JPanel panel1 = new JPanel(new GridLayout());
//layout shows it incorrectly
//JPanel panel1 = new JPanel(new FlowLayout());
panel1.setSize(200,200);
ClassDiagram c1 = new ClassDiagram();
ClassDiagram c2 = new ClassDiagram();
ClassDiagram c3 = new ClassDiagram();
panel1.add(c1);
panel1.add(c2);
panel1.add(c3);
f.add(panel1);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.show();
}Please help.
Thanks,
AndXerLayout managers.
JPanel panel1 = new JPanel(new GridLayout());GridLayout divides the availabale space into equal cells and expands each child component to fill the cell.
JPanel panel1 = new JPanel(new FlowLayout());FlowLayout attempts to show each child component at its preferred size. The preferredSize is determined by the layout manager in the process of laying out the children. For a graphic component, ie, a component with no child components, the request for the components preferredSize will return the default size which is 10,10 for JPanel. Therefore you will need to either set the preferredSize for the gtaphic component or override the getPreferredSize method and return the desired Dimension. Another limitation of FlowLayout is that it attempts to lay its children out in–line.
GridBagLayout also respects the preferredSize of child components and offers more versatility.
import java.awt.*;
import javax.swing.*;
public class CD extends JPanel
public String title = "class";
public CD()
super();
setPreferredSize(new Dimension(132,75));
setBackground(Color.WHITE);
protected void paintComponent(Graphics g)
Graphics2D g2d = (Graphics2D) g;
super.paintComponent(g2d);
g2d.setStroke(new BasicStroke(2f));
g2d.drawRect(1,1,130,25);
g2d.setFont(new Font("arial", Font.BOLD, 12));
g2d.drawString(title, 4,18);
g2d.setColor(Color.LIGHT_GRAY);
g2d.fillRect(1,25,130,25);
g2d.setColor(Color.BLACK);
g2d.drawRect(1,25,130,25);
g2d.setColor(Color.WHITE);
g2d.fillRect(1,51,130,25);
g2d.setColor(Color.BLACK);
g2d.drawRect(1,50,130,25);
public static void main(String[] args)
JPanel panel1 = new JPanel(new GridBagLayout());
// This has little affect until after realization and
// is then subject to its parent layout manager. Use
// the preferredSize for better results.
//panel1.setSize(200,200);
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(5,5,5,5);
gbc.weightx = 1.0;
gbc.weighty = 1.0;
// Add some components
int n = 5;
// and specify columns
int cols = 3;
for(int j = 0; j < n; j++) {
gbc.gridwidth = ((j+1) % cols == 0) ? GridBagConstraints.REMAINDER
: 1;
panel1.add(new CD(), gbc);
JFrame f = new JFrame("Testing ClassDiagram");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(panel1);
f.setSize(500,400);
f.setLocation(200,200);
f.setVisible(true);
} -
Using Srpy tabbed panels with slidding panels
I am very new to spry and so I am still just figuring it all
out. How I found it was I wanted a tabbed panel like the one on the
IBM website. Anyway, I am trying to
use the tabbed panels with the sliding panels and it just does not
seem to be working. I found
this
tutorial and followed the codes but it still only works as just the
tabbed panels - nothing has changed at all. Can someone tell me
what I might be doing wrong? I am attaching both my html and css
code for you to inspect.
HTML Code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8" />
<title>Untitled Document</title>
<script
src="file://///172.16.10.251/users$/kduverna/Desktop/SpryAssets/SpryTabbedPanels.js"
type="text/javascript"></script>
<link
href="file://///172.16.10.251/users$/kduverna/Desktop/SpryAssets/SpryTabbedPanels.css"
rel="stylesheet" type="text/css" />
</head>
<body>
<div id="TabbedPanels1" class="TabbedPanels">
<ul class="TabbedPanelsTabGroup">
<li class="TabbedPanelsTab" tabindex="0"><a
href=”#Tab1″>Tab 1</a></li>
<li class="TabbedPanelsTab" tabindex="0"><a
href=”#Tab1″>Tab 2</a></li>
</ul>
<div class="TabbedPanelsContentGroup">
<div class="TabbedPanelsContent">Content 1</div>
<div class="TabbedPanelsContent">Content 2</div>
</div>
</div>
<script type="text/javascript">
<!--
var TabbedPanels1 = new
Spry.Widget.TabbedPanels("TabbedPanels1");
//-->
</script>
</body>
</html>
css code to follow in post below - too many characters.and here is the css code
CSS Code
@charset "UTF-8";
/* SpryTabbedPanels.css - Revision: Spry Preview Release 1.4
/* Copyright (c) 2006. Adobe Systems Incorporated. All rights
reserved. */
/* Horizontal Tabbed Panels
* The default style for a TabbedPanels widget places all tab
buttons
* (left aligned) above the content panel.
/* This is the selector for the main TabbedPanels container.
For our
* default style, this container does not contribute anything
visually,
* but it is floated left to make sure that any floating or
clearing done
* with any of its child elements are contained completely
within the
* TabbedPanels container, to minimize any impact or
undesireable
* interaction with other floated elements on the page that
may be used
* for layout.
* If you want to constrain the width of the TabbedPanels
widget, set a
* width on the TabbedPanels container. By default, the
TabbedPanels widget
* expands horizontally to fill up available space.
* The name of the class ("TabbedPanels") used in this
selector is not
* necessary to make the widget function. You can use any
class name you
* want to style the TabbedPanels container.
.TabbedPanels {
margin: 0px;
padding: 0px;
float: left;
clear: none;
width: 100%; /* IE Hack to force proper layout when preceded
by a paragraph. (hasLayout Bug)*/
/* This is the selector for the TabGroup. The TabGroup
container houses
* all of the tab buttons for each tabbed panel in the
widget. This container
* does not contribute anything visually to the look of the
widget for our
* default style.
* The name of the class ("TabbedPanelsTabGroup") used in
this selector is not
* necessary to make the widget function. You can use any
class name you
* want to style the TabGroup container.
.TabbedPanelsTabGroup {
margin: 0px;
padding: 0px;
/* This is the selector for the TabbedPanelsTab. This
container houses
* the title for the panel. This is also the tab "button"
that the user clicks
* on to activate the corresponding content panel so that it
appears on top
* of the other tabbed panels contained in the widget.
* For our default style, each tab is positioned relatively 1
pixel down from
* where it wold normally render. This allows each tab to
overlap the content
* panel that renders below it. Each tab is rendered with a 1
pixel bottom
* border that has a color that matches the top border of the
current content
* panel. This gives the appearance that the tab is being
drawn behind the
* content panel.
* The name of the class ("TabbedPanelsTab") used in this
selector is not
* necessary to make the widget function. You can use any
class name you want
* to style this tab container.
.TabbedPanelsTab {
position: relative;
top: 1px;
float: left;
padding: 4px 10px;
margin: 0px 1px 0px 0px;
font: bold 0.7em sans-serif;
background-color: #DDD;
list-style: none;
border-left: solid 1px #CCC;
border-bottom: solid 1px #999;
border-top: solid 1px #999;
border-right: solid 1px #999;
-moz-user-select: none;
-khtml-user-select: none;
cursor: pointer;
/* This selector is an example of how to change the appearnce
of a tab button
* container as the mouse enters it. The class
"TabbedPanelsTabHover" is
* programatically added and removed from the tab element as
the mouse enters
* and exits the container.
.TabbedPanelsTabHover {
background-color: #CCC;
/* This selector is an example of how to change the
appearance of a tab button
* container after the user has clicked on it to activate a
content panel.
* The class "TabbedPanelsTabSelected" is programatically
added and removed
* from the tab element as the user clicks on the tab button
containers in
* the widget.
* As mentioned above, for our default style, tab buttons are
positioned
* 1 pixel down from where it would normally render. When the
tab button is
* selected, we change its bottom border to match the
background color of the
* content panel so that it looks like the tab is part of the
content panel.
.TabbedPanelsTabSelected {
background-color: #EEE;
border-bottom: 1px solid #EEE;
/* This selector is an example of how to make a link inside
of a tab button
* look like normal text. Users may want to use links inside
of a tab button
* so that when it gets focus, the text *inside* the tab
button gets a focus
* ring around it, instead of the focus ring around the
entire tab.
.TabbedPanelsTab a {
color: black;
text-decoration: none;
/* This is the selector for the ContentGroup. The
ContentGroup container houses
* all of the content panels for each tabbed panel in the
widget. For our
* default style, this container provides the background
color and borders that
* surround the content.
* The name of the class ("TabbedPanelsContentGroup") used in
this selector is
* not necessary to make the widget function. You can use any
class name you
* want to style the ContentGroup container.
.TabbedPanelsContentGroup {
clear: both;
border-left: solid 1px #CCC;
border-bottom: solid 1px #CCC;
border-top: solid 1px #999;
border-right: solid 1px #999;
background-color: #EEE;
/* This is the selector for the Content panel. The Content
panel holds the
* content for a single tabbed panel. For our default style,
this container
* provides some padding, so that the content is not pushed
up against the
* widget borders.
* The name of the class ("TabbedPanelsContent") used in this
selector is
* not necessary to make the widget function. You can use any
class name you
* want to style the Content container.
.TabbedPanelsContent {
padding: 4px;
/* This selector is an example of how to change the appearnce
of the currently
* active container panel. The class
"TabbedPanelsContentVisible" is
* programatically added and removed from the content element
as the panel
* is activated/deactivated.
.TabbedPanelsContentVisible {
/* Vertical Tabbed Panels
* The following rules override some of the default rules
above so that the
* TabbedPanels widget renders with its tab buttons along the
left side of
* the currently active content panel.
* With the rules defined below, the only change that will
have to be made
* to switch a horizontal tabbed panels widget to a vertical
tabbed panels
* widget, is to use the "VTabbedPanels" class on the
top-level widget
* container element, instead of "TabbedPanels".
/* This selector floats the TabGroup so that the tab buttons
it contains
* render to the left of the active content panel. A border
is drawn around
* the group container to make it look like a list container.
.VTabbedPanels .TabbedPanelsTabGroup {
float: left;
width: 10em;
height: 20em;
background-color: #EEE;
position: relative;
border-top: solid 1px #999;
border-right: solid 1px #999;
border-left: solid 1px #CCC;
border-bottom: solid 1px #CCC;
/* This selector disables the float property that is placed
on each tab button
* by the default TabbedPanelsTab selector rule above. It
also draws a bottom
* border for the tab. The tab button will get its left and
right border from
* the TabGroup, and its top border from the TabGroup or tab
button above it.
.VTabbedPanels .TabbedPanelsTab {
float: none;
margin: 0px;
border-top: none;
border-left: none;
border-right: none;
/* This selector disables the float property that is placed
on each tab button
* by the default TabbedPanelsTab selector rule above. It
also draws a bottom
* border for the tab. The tab button will get its left and
right border from
* the TabGroup, and its top border from the TabGroup or tab
button above it.
.VTabbedPanels .TabbedPanelsTabSelected {
background-color: #EEE;
border-bottom: solid 1px #999;
/* This selector floats the content panels for the widget so
that they
* render to the right of the tabbed buttons.
.VTabbedPanels .TabbedPanelsContentGroup {
clear: none;
float: left;
padding: 0px;
width: 30em;
height: 20em;
/* BEGIN: Spry Horizontal Tabbed Panels meets Sliding Door
and CSS Sprites */
/* Revision by Craig Malcolm Petrou of CPMMUG.com */
.TabbedPanels {
margin: 10px 0 5px 0;
.TabbedPanelsTab {
font-weight: bold;
font-size: 100%;
background-color: #FFF;
border: solid 0 #FFF;
.TabbedPanelsTabHover {
background-color: #FFF;
.TabbedPanelsTabSelected {
background-color: #FFF;
border-bottom: 1px solid #FFF;
position: relative;
.TabbedPanelsContentGroup {
background-color: #FFF;
ul.TabbedPanelsTabGroup a {
display: block;
ul.TabbedPanelsTabGroup li.TabbedPanelsTab {
background: url(/images/brown.png) no-repeat 0 0;
margin: 0 0 0 -1px;
padding: 0 0 0 10px;
ul.TabbedPanelsTabGroup li.TabbedPanelsTab a {
background: url(/images/brown.png) no-repeat 100% 0;
padding: 7px 10px 5px 0;
ul.TabbedPanelsTabGroup li.TabbedPanelsTabSelected {
background: url(/images/brown.png) no-repeat 0 -41px;
ul.TabbedPanelsTabGroup li.TabbedPanelsTabSelected a {
background: url(/images/brown.png) no-repeat 100% -41px;
/* END: Spry Horizontal Tabbed Panels meets Sliding Door and
CSS Sprites */
Also - is there a way to get rounded corners on the tabs in
spry? Any good tutorials I can follow about spry - more
specifically about using widgets and effects together.
Thanks so much -
How can i fill color Recent panel of colorchooser
hi all,
i want to set a color for recent panel of color chooser,
if i set color for the color chooser
colorChooser.setColor(Color.Red)it set color for the preview panel that's it, i want to fill in recent panel also,
any suggestion?
thanks
dayaIt looks like it's hard to do easily, because DefaultSwatchChooserPanel (used by JColorChooser) is a private class.
So I copied its code into MyChooserPanel and modified it a little bit, now ColorChooser class has additional method
setRecentColors(Color[] c);
I deleted all Sun comments to make it shorter (probably you need to leave them if you want to use the class legally, I'm not sure).
This is a fast and ugly solution :(
also setRecentColors() should be called by Swing dispatcher thread
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.accessibility.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.colorchooser.*;
public class ColorChooser extends JColorChooser {
private MyChooserPanel mp;
public static void main(String[] args) {
SwingUtilities.invokeLater(
new Runnable(){
public void run() {
JFrame myFrame = new JFrame("ooo");
myFrame.setLayout(new FlowLayout());
final ColorChooser cc = new ColorChooser();
myFrame.add(cc);
JButton b = new JButton("Color");
myFrame.add(b);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
cc.setRecentColors(new Color[]{Color.GREEN,Color.RED,Color.BLUE});
myFrame.pack();
myFrame.setSize(new Dimension(500, 420));
myFrame.setVisible(true);
myFrame.setLocationRelativeTo(null);
public ColorChooser(){
super();
AbstractColorChooserPanel[] p=getChooserPanels();
//remove all Panels
for (AbstractColorChooserPanel e : p) {
removeChooserPanel(e);
//add panels back
for (AbstractColorChooserPanel e : p) {
if(e.getClass().toString().contains("DefaultSwatchChooserPanel")){
mp = new MyChooserPanel(); //if this is swatch panel, substitute it
addChooserPanel(mp);
else
addChooserPanel(e);
public void setRecentColors(Color[] cols){
mp.setRecentColors(cols);
//Copy of standard DefaultSwatchChooserPanel
// with minor changes: added setRecentColors()
//modified RecentSwatchPanel: added setColors()
class MyChooserPanel extends AbstractColorChooserPanel {
SwatchPanel swatchPanel;
RecentSwatchPanel recentSwatchPanel;
MouseListener mainSwatchListener;
MouseListener recentSwatchListener;
private String recentStr = UIManager.getString("ColorChooser.swatchesRecentText");
public MyChooserPanel() {
super();
setInheritsPopupMenu(true);
public String getDisplayName() {
return UIManager.getString("ColorChooser.swatchesNameText");
public int getMnemonic() {
return getInt("ColorChooser.swatchesMnemonic", -1);
int getInt(Object key, int defaultValue) {
Object value = UIManager.get(key);
if (value instanceof Integer) {
return ((Integer)value).intValue();
if (value instanceof String) {
try {
return Integer.parseInt((String)value);
catch (NumberFormatException nfe) {}
return defaultValue;
public int getDisplayedMnemonicIndex() {
return getInt("ColorChooser.swatchesDisplayedMnemonicIndex", -1);
public Icon getSmallDisplayIcon() {
return null;
public Icon getLargeDisplayIcon() {
return null;
public void installChooserPanel(JColorChooser enclosingChooser) {
super.installChooserPanel(enclosingChooser);
protected void buildChooser() {
GridBagLayout gb = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
JPanel superHolder = new JPanel(gb);
swatchPanel = new MainSwatchPanel();
swatchPanel.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,
getDisplayName());
swatchPanel.setInheritsPopupMenu(true);
recentSwatchPanel = new RecentSwatchPanel();
recentSwatchPanel.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY,
recentStr);
mainSwatchListener = new MainSwatchListener();
swatchPanel.addMouseListener(mainSwatchListener);
recentSwatchListener = new RecentSwatchListener();
recentSwatchPanel.addMouseListener(recentSwatchListener);
JPanel mainHolder = new JPanel(new BorderLayout());
Border border = new CompoundBorder(new LineBorder(Color.black),
new LineBorder(Color.white));
mainHolder.setBorder(border);
mainHolder.add(swatchPanel, BorderLayout.CENTER);
gbc.anchor = GridBagConstraints.LAST_LINE_START;
gbc.gridwidth = 1;
gbc.gridheight = 2;
Insets oldInsets = gbc.insets;
gbc.insets = new Insets(0, 0, 0, 10);
superHolder.add(mainHolder, gbc);
gbc.insets = oldInsets;
recentSwatchPanel.addMouseListener(recentSwatchListener);
recentSwatchPanel.setInheritsPopupMenu(true);
JPanel recentHolder = new JPanel(new BorderLayout());
recentHolder.setBorder(border);
recentHolder.setInheritsPopupMenu(true);
recentHolder.add(recentSwatchPanel, BorderLayout.CENTER);
JLabel l = new JLabel(recentStr);
l.setLabelFor(recentSwatchPanel);
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbc.gridheight = 1;
gbc.weighty = 1.0;
superHolder.add(l, gbc);
gbc.weighty = 0;
gbc.gridheight = GridBagConstraints.REMAINDER;
gbc.insets = new Insets(0, 0, 0, 2);
superHolder.add(recentHolder, gbc);
superHolder.setInheritsPopupMenu(true);
add(superHolder);
public void uninstallChooserPanel(JColorChooser enclosingChooser) {
super.uninstallChooserPanel(enclosingChooser);
swatchPanel.removeMouseListener(mainSwatchListener);
recentSwatchPanel.removeMouseListener(recentSwatchListener);
swatchPanel = null;
recentSwatchPanel = null;
mainSwatchListener = null;
recentSwatchListener = null;
removeAll(); // strip out all the sub-components
public void updateChooser() {
class RecentSwatchListener extends MouseAdapter implements Serializable {
public void mousePressed(MouseEvent e) {
Color color = recentSwatchPanel.getColorForLocation(e.getX(), e.getY());
getColorSelectionModel().setSelectedColor(color);
class MainSwatchListener extends MouseAdapter implements Serializable {
public void mousePressed(MouseEvent e) {
Color color = swatchPanel.getColorForLocation(e.getX(), e.getY());
getColorSelectionModel().setSelectedColor(color);
recentSwatchPanel.setMostRecentColor(color);
public void setRecentColors(Color[] cols) {
recentSwatchPanel.setColors(cols);
class SwatchPanel extends JPanel {
protected Color[] colors;
protected Dimension swatchSize;
protected Dimension numSwatches;
protected Dimension gap;
public SwatchPanel() {
initValues();
initColors();
setToolTipText(""); // register for events
setOpaque(true);
setBackground(Color.white);
setRequestFocusEnabled(false);
setInheritsPopupMenu(true);
public boolean isFocusTraversable() {
return false;
protected void initValues() {
public void paintComponent(Graphics g) {
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
for (int row = 0; row < numSwatches.height; row++) {
int y = row * (swatchSize.height + gap.height);
for (int column = 0; column < numSwatches.width; column++) {
g.setColor(getColorForCell(column, row));
int x;
if ((!this.getComponentOrientation().isLeftToRight()) &&
(this instanceof RecentSwatchPanel)) {
x = (numSwatches.width - column - 1) * (swatchSize.width + gap.width);
else {
x = column * (swatchSize.width + gap.width);
g.fillRect(x, y, swatchSize.width, swatchSize.height);
g.setColor(Color.black);
g.drawLine(x + swatchSize.width - 1, y, x + swatchSize.width - 1, y + swatchSize.height - 1);
g.drawLine(x, y + swatchSize.height - 1, x + swatchSize.width - 1, y + swatchSize.height - 1);
public Dimension getPreferredSize() {
int x = numSwatches.width * (swatchSize.width + gap.width) - 1;
int y = numSwatches.height * (swatchSize.height + gap.height) - 1;
return new Dimension(x, y);
protected void initColors() {
public String getToolTipText(MouseEvent e) {
Color color = getColorForLocation(e.getX(), e.getY());
return color.getRed() + ", " + color.getGreen() + ", " + color.getBlue();
public Color getColorForLocation(int x, int y) {
int column;
if ((!this.getComponentOrientation().isLeftToRight()) &&
(this instanceof RecentSwatchPanel)) {
column = numSwatches.width - x / (swatchSize.width + gap.width) - 1;
else {
column = x / (swatchSize.width + gap.width);
int row = y / (swatchSize.height + gap.height);
return getColorForCell(column, row);
private Color getColorForCell(int column, int row) {
return colors[(row * numSwatches.width) + column]; // (STEVE) - change data orientation here
class RecentSwatchPanel extends SwatchPanel {
protected void initValues() {
swatchSize = UIManager.getDimension("ColorChooser.swatchesRecentSwatchSize");
numSwatches = new Dimension(5, 7);
gap = new Dimension(1, 1);
public void setColors(Color[] cols) {
Color defaultRecentColor = UIManager.getColor("ColorChooser.swatchesDefaultRecentColor");
int numColors = numSwatches.width * numSwatches.height;
colors = new Color[numColors];
for (int i = 0; i < numColors ; i++) {
Color c;
if (i < cols.length)
c = cols;
else
c = defaultRecentColor;
colors[i] = c;
repaint();
protected void initColors() {
Color defaultRecentColor = UIManager.getColor("ColorChooser.swatchesDefaultRecentColor");
int numColors = numSwatches.width * numSwatches.height;
colors = new Color[numColors];
for (int i = 0; i < numColors ; i++) {
colors[i] = defaultRecentColor;
public void setMostRecentColor(Color c) {
System.arraycopy(colors, 0, colors, 1, colors.length - 1);
colors[0] = c;
repaint();
class MainSwatchPanel extends SwatchPanel {
protected void initValues() {
swatchSize = UIManager.getDimension("ColorChooser.swatchesSwatchSize");
numSwatches = new Dimension(31, 9);
gap = new Dimension(1, 1);
protected void initColors() {
int[] rawValues = initRawValues();
int numColors = rawValues.length / 3;
colors = new Color[numColors];
for (int i = 0; i < numColors ; i++) {
colors[i] = new Color(rawValues[(i * 3)], rawValues[(i * 3) + 1], rawValues[(i * 3) + 2]);
private int[] initRawValues() {
int[] rawValues = {
255, 255, 255, // first row.
204, 255, 255,
204, 204, 255,
204, 204, 255,
204, 204, 255,
204, 204, 255,
204, 204, 255,
204, 204, 255,
204, 204, 255,
204, 204, 255,
204, 204, 255,
255, 204, 255,
255, 204, 204,
255, 204, 204,
255, 204, 204,
255, 204, 204,
255, 204, 204,
255, 204, 204,
255, 204, 204,
255, 204, 204,
255, 204, 204,
255, 255, 204,
204, 255, 204,
204, 255, 204,
204, 255, 204,
204, 255, 204,
204, 255, 204,
204, 255, 204,
204, 255, 204,
204, 255, 204,
204, 255, 204,
204, 204, 204, // second row.
153, 255, 255,
153, 204, 255,
153, 153, 255,
153, 153, 255,
153, 153, 255,
153, 153, 255,
153, 153, 255,
153, 153, 255,
153, 153, 255,
204, 153, 255,
255, 153, 255,
255, 153, 204,
255, 153, 153,
255, 153, 153,
255, 153, 153,
255, 153, 153,
255, 153, 153,
255, 153, 153,
255, 153, 153,
255, 204, 153,
255, 255, 153,
204, 255, 153,
153, 255, 153,
153, 255, 153,
153, 255, 153,
153, 255, 153,
153, 255, 153,
153, 255, 153,
153, 255, 153,
153, 255, 204,
204, 204, 204, // third row
102, 255, 255,
102, 204, 255,
102, 153, 255,
102, 102, 255,
102, 102, 255,
102, 102, 255,
102, 102, 255,
102, 102, 255,
153, 102, 255,
204, 102, 255,
255, 102, 255,
255, 102, 204,
255, 102, 153,
255, 102, 102,
255, 102, 102,
255, 102, 102,
255, 102, 102,
255, 102, 102,
255, 153, 102,
255, 204, 102,
255, 255, 102,
204, 255, 102,
153, 255, 102,
102, 255, 102,
102, 255, 102,
102, 255, 102,
102, 255, 102,
102, 255, 102,
102, 255, 153,
102, 255, 204,
153, 153, 153, // fourth row
51, 255, 255,
51, 204, 255,
51, 153, 255,
51, 102, 255,
51, 51, 255,
51, 51, 255,
51, 51, 255,
102, 51, 255,
153, 51, 255,
204, 51, 255,
255, 51, 255,
255, 51, 204,
255, 51, 153,
255, 51, 102,
255, 51, 51,
255, 51, 51,
255, 51, 51,
255, 102, 51,
255, 153, 51,
255, 204, 51,
255, 255, 51,
204, 255, 51,
153, 255, 51,
102, 255, 51,
51, 255, 51,
51, 255, 51,
51, 255, 51,
51, 255, 102,
51, 255, 153,
51, 255, 204,
153, 153, 153, // Fifth row
0, 255, 255,
0, 204, 255,
0, 153, 255,
0, 102, 255,
0, 51, 255,
0, 0, 255,
51, 0, 255,
102, 0, 255,
153, 0, 255,
204, 0, 255,
255, 0, 255,
255, 0, 204,
255, 0, 153,
255, 0, 102,
255, 0, 51,
255, 0 , 0,
255, 51, 0,
255, 102, 0,
255, 153, 0,
255, 204, 0,
255, 255, 0,
204, 255, 0,
153, 255, 0,
102, 255, 0,
51, 255, 0,
0, 255, 0,
0, 255, 51,
0, 255, 102,
0, 255, 153,
0, 255, 204,
102, 102, 102, // sixth row
0, 204, 204,
0, 204, 204,
0, 153, 204,
0, 102, 204,
0, 51, 204,
0, 0, 204,
51, 0, 204,
102, 0, 204,
153, 0, 204,
204, 0, 204,
204, 0, 204,
204, 0, 204,
204, 0, 153,
204, 0, 102,
204, 0, 51,
204, 0, 0,
204, 51, 0,
204, 102, 0,
204, 153, 0,
204, 204, 0,
204, 204, 0,
204, 204, 0,
153, 204, 0,
102, 204, 0,
51, 204, 0,
0, 204, 0,
0, 204, 51,
0, 204, 102,
0, 204, 153,
0, 204, 204,
102, 102, 102, // seventh row
0, 153, 153,
0, 153, 153,
0, 153, 153,
0, 102, 153,
0, 51, 153,
0, 0, 153,
51, 0, 153,
102, 0, 153,
153, 0, 153,
153, 0, 153,
153, 0, 153,
153, 0, 153,
153, 0, 153,
153, 0, 102,
153, 0, 51,
153, 0, 0,
153, 51, 0,
153, 102, 0,
153, 153, 0,
153, 153, 0,
153, 153, 0,
153, 153, 0,
153, 153, 0,
102, 153, 0,
51, 153, 0,
0, 153, 0,
0, 153, 51,
0, 153, 102,
0, 153, 153,
0, 153, 153,
51, 51, 51, // eigth row
0, 102, 102,
0, 102, 102,
0, 102, 102,
0, 102, 102,
0, 51, 102,
0, 0, 102,
51, 0, 102,
102, 0, 102,
102, 0, 102,
102, 0, 102,
102, 0, 102,
102, 0, 102,
102, 0, 102,
102, 0, 102,
102, 0, 51,
102, 0, 0,
102, 51, 0,
102, 102, 0,
102, 102, 0,
102, 102, 0,
102, 102, 0,
102, 102, 0,
102, 102, 0,
102, 102, 0,
51, 102, 0,
0, 102, 0,
0, 102, 51,
0, 102, 102,
0, 102, 102,
0, 102, 102,
0, 0, 0, // ninth row
0, 51, 51,
0, 51, 51,
0, 51, 51,
0, 51, 51,
0, 51, 51,
0, 0, 51,
51, 0, 51,
51, 0, 51,
51, 0, 51,
51, 0, 51,
51, 0, 51,
51, 0, 51,
51, 0, 51,
51, 0, 51,
51, 0, 51,
51, 0, 0,
51, 51, 0,
51, 51, 0,
51, 51, 0,
51, 51, 0,
51, 51, 0,
51, 51, 0,
51, 51, 0,
51, 51, 0,
0, 51, 0,
0, 51, 51,
0, 51, 51,
0, 51, 51,
0, 51, 51,
51, 51, 51 };
return rawValues; -
I have nearly filled my iCloud storage with pictures. If I subscribe to iTunes match, will I still be able to access music via the cloud, or will I have to buy more storage space? Cheers.
Yes, but... you'll have to first index her music through your iTM subscription. So... you'd have to add her music into your own library first. Which.... would defeat the point of iTM I suspect in your case.
-
Get search criteria from query panel with table
hi guys,
i have a query panel with table that i created from a VO.
i use the all queryable attribute in the generated DataControl.
i hv a requirement to update the database value with the same search criteria with the query panel.
but i want the submitted search criteria, not only written in the query panel criteria.
i'm using JDEV & BPM 11.1.1.6
i've already tried to get the criteria using
QueryModel queryModel = getQueryPanel().getModel();
QueryDescriptor queryDescriptor = queryModel.getSystemQueries().get(0);
ConjunctionCriterion cc = queryDescriptor.getConjunctionCriterion();
for(int i=0;i<cc.getCriterionList().size();i++){
AttributeCriterion ac = (AttributeCriterion)cc.getCriterionList().get(i);
System.out.println("DEBUG LABEL : " + ac.getAttribute().getLabel());
System.out.println("DEBUG VALUE : " + ac.getValues().get(0));
} but it only get the value that filled in the search criteria input text, not the criteria that already been searched and viewed in the table
my other question is, can i override the search button function ? so i can add a custom method to save the search criteria to my temporary variable.
thanks
Edited by: Juw on May 29, 2013 2:05 AMIs this https://blogs.oracle.com/jdevotnharvest/entry/how-to_tell_the_viewcriteria_a_user_chose_in_an_afquery_component or http://www.learnoracleadf.com/2013/05/programatic-handle-to-adf-query.html what you are looking for?
Timo -
Automatic Resizing of panel with drawings added to a scrollPane
I have a Panel with rectangles text and arcs drawn .and it is added to a scrollPane.both vertical and Horizontal scrollbars are enabled for scrollPane.My problem is that i have to draw arcs connecting these rectangles with text enclosed in it. and when i connect two rectangles a span is formed connecting the two..and as hierarchy goes deeper ie connecting spans of already linked rectangles with similar spans..There wont be enough space at top for arc to be drawn..So ive to either readjust all objects related with drawings in panel or is there any other way to increase panel size automatically as drawings need more space..Please suggest me some method for this problem
Panels Preffered size is set as (3000,1000) and TextRectangles are drawn in panel Cordinates of textRectangle are set in setTextRectangle method and all further drawings connecting rectangle are done by mouse clicks on specific rectangles.
and layout in setTextRectangle is TextLayout of the text enclosed in rectangles.So when i coordinates for arc drawn exceeds the panel should i call separate method for resetting panel size is that what you have suggested
screen_Resolution = Toolkit.getDefaultToolkit().
getScreenResolution();
screen_Width = Toolkit.getDefaultToolkit().
getScreenSize().width;
screen_Height = Toolkit.getDefaultToolkit().
getScreenSize().height;
public void setTextRectangle(Graphics g, Font font)
Graphics2D g2 = (Graphics2D) g;
FontMetrics metrics= g.getFontMetrics (font);
int textHeight = metrics.getHeight();
int left=textHeight;
int yCordRectangle=(int)(screen_Height/5);
for (int i = 0; i < layouts.size (); i++) {
int top=(int)(screen_Resolution*2);
for (int j = 0; j < layouts.get (i).size (); j++) {
top += textHeight;
TextRectangle textRectangle=new TextRectangle(left,yCordRectangle,wrapWidth,top-150);
addtoarray( textRectangle, rectangles);
left += wrapWidth + textHeight;
Maybe you are looking for
-
I'm buying a Mac mini in September - so I will have Snow Leopard - to use with the latest version of Logic and the latest version of Pro Tools and use for my college work and recording my band. I plan on using an M-Audio MobilePre USB, external hard
-
Security updates takes long time to install through Software Center
Hi Folks, We have a setup with SCCM 2012 R2 CU4 as a Primary Site server where SUP also enabled. I deployed the windows security updates to the test servers collection by deployment type as Available. I verified in test servers that all the deployed
-
Acrobat 9.0 for Window - Cannot create PDF Printer
I can't create a printer as non of the drivers in "C:\program Files\adobe\Acrobat 9.0\Acrobat\Xtras\AdobePDF" work. Re-installing does not work either. I tried installing older verions 7 & 8, both created Adobe PDF Printer... when installing version
-
713x BDA Analog Capture defaults to SVideo?
I am having trouble using the MSI TV@nywhere Plus to stream live video from the composite input to a provider like ustream.tv. Using a free version of webcamxp/webcam7, I am able to view/stream video ONLY when I select '713x BDA Analog Capture', then
-
Is there a way to duplicate and audio segment- copy and paste does not do it.