How can I set a full width for a tabbed pane? I've tried working with the following code:
UIDefaults def = UIManager.getLookAndFeelDefaults();
def.put( "TabbedPane.tabInsets", new Insets(0, 0, 0, 250) );
But, it doesn't seem to increase the size fully, whatever I work with. It either creates two rows, or isn't full length.
Picture to understand the problem:
http://s8.postimage.org/lr47nm9tx/tabbedpanefull.png
Related
I have a Java Swing form and JLabel like this:
What I need to do is inserting a gap in the beginning of the JLabel:
So it will not stuck to the border line.
Note 1 : I already used jLabName.setIconTextGap(35); but it did the below:
I need to insert the gap before the icon not after it!
Note 2 : The Border Setting And Type And other setting:
You can use compound borders for that.
For Example.
//get border of your component which is button as you say
Border border = myButton.getBorder();
//create a new empty border with name it margin
Border margin = new EmptyBorder(0,10,0,0); //top 0, left 10 , bottom 0, right 0
//now set compound border to your button(component), with margin
myButton.setBorder(new CompoundBorder(border, margin));
//NOTE: CompoundBorder accepts two borders as arguments, first one is inner border and last one is outer border
Fixed it with the following code:
a1.setBorder(new CompoundBorder(new EtchedBorder(), BorderFactory.createEmptyBorder(1, 8, 1, 1)));
I'm trying to use purely JNA to create a borderless window and also control its size. I can create the window using this:
String windowClass = new String("NewWindowClass");
HMODULE hInst = Kernel32.INSTANCE.GetModuleHandle("");
WNDCLASSEX wClass = new WNDCLASSEX();
wClass.hInstance = hInst;
wClass.lpfnWndProc = Main.this;
wClass.lpszClassName = windowClass;
User32.INSTANCE.RegisterClassEx(wClass);
HWND hWnd = User32.INSTANCE.CreateWindowEx(User32.WS_EX_TOPMOST, windowClass, "This is the window title", 0, 0, 0, 50, 50, null, null, hInst, null);
User32.INSTANCE.ShowWindow(hWnd, 1);
The 50, 50 being the width and height of the window. This was sourced from some JNA demo code (lines 54-74). I can remove the borders by adding this code after it:
long style = User32.INSTANCE.GetWindowLong(hWnd, User32.GWL_STYLE);
style &= (~User32.WS_CAPTION);
User32.INSTANCE.SetWindowLong(hWnd, User32.GWL_STYLE, (int) style);
So now you can see that there's an un-decorated window, however unlike the expected 50x50 dimensions, the size still seems to be affected by the caption bar and border but I just don't know how to stop it. I tried a bunch of windows styles and extended window styles with no luck.
Just to be sure I could get it the way I wanted, I created a simple JFrame:
JFrame frame = new JFrame("Title");
frame.setUndecorated(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(50, 50);
frame.setVisible(true);
Using Microsoft Spy++, I cross referenced the window styles to make sure they matched and even with the same styles, I just couldn't get it to change to the size I want it. So I'm guessing this isn't something to do with the window styles but I don't know where to go from here. Anyone have any info on this?
Thanks in advance.
In my application, I need to word wrap Labels, which are contained in a JPanel (with GridBagLayout), which in turn is contained in a JScrollPane, which is contained in a resizable JFrame. The text should always be as wide as the Scrollpane allows(i.e. be completly visible at once). I tried multiple things already:
Putting tags around the text.
Result: Nothing
Putting on the Text
Result: Wraps, but with static width (does not respond to the Frame being resized) (duh)
Putting on the Text
Result: Nothing
Using a JTextArea, as in https://stackoverflow.com/a/26426585/4936150
Result: Appears to work at first, when the width of the Frame is increased, the words get "unwrapped" (so they are all on one line), but when the width is decreased afterwards, it will stay that way and not "wrap back". Also, weirdly doesn't work in the Nimbus L&F
Implementing Scrollable on the JPanel and returning true from getScrollableTracksViewportWidth()
Result: Works, but I DO want it to scroll horizontally if the Frame is too small for other Components
For reference, here is the source for my Panel class, without any wrapping:
public class ProgPanel extends JPanel {
/**
* Create the panel.
*/
public ProgPanel() {
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{0};
gridBagLayout.rowHeights = new int[]{59, 0, 0};
gridBagLayout.columnWeights = new double[]{1.0};
gridBagLayout.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
setLayout(gridBagLayout);
JLabel lblName = new JLabel("Long, long text taht needs to be wrapped, because it is displayed in a very big font on a kindof small screen, bla bla bla bhlergh lol rofl 1337");
GridBagConstraints gbc_lblName = new GridBagConstraints();
gbc_lblName.gridwidth = 2;
gbc_lblName.anchor = GridBagConstraints.WEST;
gbc_lblName.insets = new Insets(0, 0, 5, 0);
gbc_lblName.gridwidth = 1;
gbc_lblName.gridx = 0;
gbc_lblName.gridy = 0;
add(lblName, gbc_lblName);
lblName.setBorder(new EmptyBorder(10, 5, 0, 10));
lblName.setIconTextGap(10);
lblName.setIcon(new ImageIcon("someicon.png"));
lblName.setFont(getFont().deriveFont(Font.BOLD+Font.ITALIC, 48));
}
}
EDIT: Here is the implementation using a JTextArea, which will only grow in width, but not shrink: https://pastebin.com/egMXfwK1 (Pastebin due to long length and tedious SO formatting)
EDIT2: Here are some pictures showing the issue: http://imgur.com/a/mhtV9
When i execute the code bellow and add in mySimpleXYPlot.getGraphWidget().getBorderPaint().setColor(Color.WHITE);
the app crashes when i launch it on my device.
what i'm trying to accomplish is getting rid of the black border around the entire graph. it is about 2cm thick on located on the top, left and bottom sides of the chart. Is there any way i can get rid of this black border?
public class MainActivity extends Activity {
private XYPlot mySimpleXYPlot;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a couple arrays of y-values to plot:
Number[] days = { 1 , 2 , 3 , 4 , 5 , 6 , 7 };
Number[] values = { 380, 1433, 1965, 3200, 3651, 3215, 3217 };
// initialize our XYPlot reference:
mySimpleXYPlot = (XYPlot) findViewById(R.id.mySimpleXYPlot);
mySimpleXYPlot.getBackgroundPaint().setColor(Color.WHITE);
mySimpleXYPlot.setBorderStyle(XYPlot.BorderStyle.NONE, null, null);
mySimpleXYPlot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE);
mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);
// Domain
mySimpleXYPlot.getGraphWidget().setDomainLabelPaint(null);
mySimpleXYPlot.getGraphWidget().setDomainOriginLinePaint(null);
mySimpleXYPlot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, days.length);
mySimpleXYPlot.setDomainValueFormat(new DecimalFormat("0"));
//Range
mySimpleXYPlot.getGraphWidget().setRangeOriginLinePaint(null);
mySimpleXYPlot.setRangeStep(XYStepMode.SUBDIVIDE, values.length);
mySimpleXYPlot.setRangeValueFormat(new DecimalFormat("0"));
//Remove legend
mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getLegendWidget());
mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getDomainLabelWidget());
mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getRangeLabelWidget());
mySimpleXYPlot.getLayoutManager().remove(mySimpleXYPlot.getTitleWidget());
// Turn the above arrays into XYSeries':
XYSeries series1 = new SimpleXYSeries(
Arrays.asList(days),
Arrays.asList(values),
"Series1"); // Set the display title of the series
// Create a formatter to use for drawing a series using LineAndPointRenderer:
LineAndPointFormatter series1Format = new LineAndPointFormatter(
Color.rgb(0, 200, 0), // line color
Color.rgb(0, 100, 0), // point color
Color.CYAN); // fill color
// setup our line fill paint to be a slightly transparent gradient:
Paint lineFill = new Paint();
lineFill.setAlpha(200);
lineFill.setShader(new LinearGradient(0, 0, 0, 250, Color.WHITE, Color.GREEN, Shader.TileMode.MIRROR));
series1Format.setFillPaint(lineFill);
// add a new series' to the xyplot:
mySimpleXYPlot.addSeries(series1, series1Format);
// by default, AndroidPlot displays developer guides to aid in laying out your plot.
// To get rid of them call disableAllMarkup():
mySimpleXYPlot.disableAllMarkup();
}
}
If you want to get rid of all of the color behind your graph, you will need the following three methods. Each of which gets rid of different parts.
//This gets rid of the gray grid
mySimpleXYPlot.getGraphWidget().getGridBackgroundPaint().setColor(Color.TRANSPARENT);
//This gets rid of the black border (up to the graph) there is no black border around the labels
mysimpleXYPlot.getBackgroundPaint().setColor(Color.TRANSPARENT);
//This gets rid of the black behind the graph
mySimpleXYPlot.getGraphWidget().getBackgroundPaint().setColor(Color.TRANSPARENT);
//With a new release of AndroidPlot you have to also set the border paint
plot.getBorderPaint().setColor(Color.TRANSPARENT);
Hope this helps.
Border line can be hidden by this method:
plot.setBorderPaint(null);
plot.setPlotMargins(0, 0, 0, 0);
I was able to figure out how to fix the graph with this information but I had to pull together the information from several of these posts. There appears to be 4 different background areas:
* grid (and axis labels)
* area around the graph
* border around the graph.
* margin around the border
The background color for the grid and range/domain labels are set using
plot.getGraphWidget().getBackgroundPaint().setColor(background_color);
The area round the grid can get set by:
plot.getBackgroundPaint().setColor(background_color);
This still leaves a border that is drawn around the graph. You can either get rid of the border:
plot.setBorderPaint(null);
or set the background color
plot.getBorderPaint().setColor(background_color);
This leaves the margin around the entire plot. This can be removed using
plot.setPlotMargins(0, 0, 0, 0);
There should be a way to change the color for the margin instead of just removing it but didn't bother to figure that out.
I created a slider inside of a table like shown in the following code example as I know that the minimum width of the background is used for the slider width:
public OptionScreen(MainClass game) {
super(game);
preference = new PreferencesHelper();
font = this.getDefaultFont(25);
this.table = new Table();
if (Config.DEBUG)
this.table.debug();
// add volumenlabel
LabelStyle style = new LabelStyle(font, Color.WHITE);
volumenLabel = new Label(Config.VOLUMEN_LABLE, style);
table.add(volumenLabel).colspan(2);
table.row();
// add slider
Skin skin = new Skin();
skin.add("sliderbackground",
this.game.manager.get("data/sliderbackground.png"));
skin.add("sliderknob", this.game.manager.get("data/sliderknob.png"));
SliderStyle sliderStyle = new SliderStyle();
sliderStyle.background = skin.getDrawable("sliderbackground");
sliderStyle.background.setMinWidth(600f);
sliderStyle.knob = skin.getDrawable("sliderknob");
volumenSlider = new Slider(0f, 1f, 0.1f, false, sliderStyle);
volumenSlider.setValue(preference.getVolumen()); // load current volumen
volumenSlider.addListener(new ChangeListener() {
#Override
public void changed(ChangeEvent event, Actor actor) {
volumeValue.setText(String.format("%.01f",
volumenSlider.getValue()));
// sett the preference
preference.setVolumen(volumenSlider.getValue());
}
});
// add volslider to stage
table.add(volumenSlider);
volumenLabel.invalidate();
// table
style = new LabelStyle(font, Color.WHITE);
// set current volumen
volumeValue = new Label(
String.format("%.01f", volumenSlider.getValue()), style);
volumenLabel.setAlignment(2);
table.add(volumeValue).width(50f);
table.row();
initBackButton();
// init table
table.setPosition(Config.VIRTUAL_VIEW_WIDTH / 2,
Config.VIRTUAL_VIEW_HEIGHT / 2 - Config.BLOCK_SIZE * 10);
// add a nice fadeIn to the whole table :)
table.setColor(0, 0, 0, 0f);
table.addAction(Actions.fadeIn(2f)); // alpha fade
table.addAction(Actions.moveTo(Config.VIRTUAL_VIEW_WIDTH / 2,
Config.VIRTUAL_VIEW_HEIGHT / 2, 2f)); // move to center of the
// screen
// add to stage
this.stage.addActor(table);
}
The slide is inside a table with no width set. I already took a look if the width is set and if the calculation for the prefWidth of the slider does uses the set 600f.
Math.max(style.knob == null ? 0 : style.knob.getMinWidth(), style.background.getMinWidth())
Is the calculation for the width of the slider inside the Sliderclass. If I calculate that and log it, it loggs the desired 600f.
Everything seems right to me but the slider is rendered way to small for the 600 I set.
The background and knobtextures are 24x24.
So I hope you guys can tell me what I am doing wrong.
The folution is, that it's inside an table so the width is defined by the table width attibut for the spec. col and row.
So the fix is pretty short:
table.add(volumenSlider).width(600).height(60);
And its 600width and 60 height.
The wiki got edited to be more clear about this:
UI widgets do not set their own size and position. Instead, the parent widget sets the size and position of each child. Widgets provide a minimum, preferred, and maximum size that the parent can use as hints. Some parent widgets, such as Table, can be given constraints on how to size and position the children. To give a widget a specific size in a layout, the widget's minimum, preferred, and maximum size are left alone and size constraints are set in the parent.
Layout at Wiki
speedSlider.getStyle().knob.setMinHeight(100)